trunk/src/mess/machine/thomflop.c
| r29179 | r29180 | |
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | /* build a sector, with header & space */ |
| 118 | | int thomson_state::thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size ) |
| 118 | int thomson_state::thom_floppy_make_sector( legacy_floppy_image_device* img, chrn_id id, UINT8* dst, int sector_size ) |
| 119 | 119 | { |
| 120 | 120 | if ( sector_size == 128 ) |
| 121 | 121 | { |
| 122 | 122 | /* single density */ |
| 123 | 123 | memset( dst, 0x00, 6 ); /* synchro bytes */ |
| 124 | 124 | dst[ 6 ] = 0xfb; /* data field mark */ |
| 125 | | floppy_drive_read_sector_data |
| 126 | | ( img, id.H, id.data_id, dst + 7, sector_size ); |
| 125 | img->floppy_drive_read_sector_data |
| 126 | ( id.H, id.data_id, dst + 7, sector_size ); |
| 127 | 127 | dst[ sector_size + 7 ] = 0; /* TODO: CRC */ |
| 128 | 128 | dst[ sector_size + 8 ] = 0; /* TODO: CRC */ |
| 129 | 129 | memset( dst + sector_size + 9, 0xff, 22 ); /* end mark */ |
| r29179 | r29180 | |
| 134 | 134 | /* double density */ |
| 135 | 135 | memset( dst, 0xa1, 3 ); /* synchro bytes */ |
| 136 | 136 | dst[ 3 ] = 0xfb; /* data field mark */ |
| 137 | | floppy_drive_read_sector_data |
| 138 | | ( img, id.H, id.data_id, dst + 4, sector_size ); |
| 137 | img->floppy_drive_read_sector_data |
| 138 | ( id.H, id.data_id, dst + 4, sector_size ); |
| 139 | 139 | dst[ sector_size + 4 ] = 0; /* TODO: CRC */ |
| 140 | 140 | dst[ sector_size + 5 ] = 0; /* TODO: CRC */ |
| 141 | 141 | memset( dst + sector_size + 6, 0xF7, 74 ); /* end mark */ |
| r29179 | r29180 | |
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /* build a whole track */ |
| 149 | | int thomson_state::thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side ) |
| 149 | int thomson_state::thom_floppy_make_track( legacy_floppy_image_device* img, UINT8* dst, int sector_size, int side ) |
| 150 | 150 | { |
| 151 | 151 | UINT8 space = ( sector_size == 128 ) ? 0xff : 0; |
| 152 | 152 | UINT8* org = dst; |
| r29179 | r29180 | |
| 154 | 154 | int nb; |
| 155 | 155 | |
| 156 | 156 | /* go to start of track */ |
| 157 | | while ( ! floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) ) |
| 157 | while ( ! img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) ) |
| 158 | 158 | { |
| 159 | | if ( ! floppy_drive_get_next_id( img, side, &id ) ) |
| 159 | if ( ! img->floppy_drive_get_next_id( side, &id ) ) |
| 160 | 160 | return 0; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /* for each sector... */ |
| 164 | 164 | for ( nb = 0; nb < 16; nb++ ) |
| 165 | 165 | { |
| 166 | | if ( ! floppy_drive_get_next_id( img, side, &id ) ) |
| 166 | if ( ! img->floppy_drive_get_next_id( side, &id ) ) |
| 167 | 167 | break; |
| 168 | 168 | |
| 169 | 169 | memset( dst, space, THOM_SIZE_SYNCHRO ); dst += THOM_SIZE_SYNCHRO; |
| r29179 | r29180 | |
| 171 | 171 | memset( dst, space, THOM_SIZE_SYNCHRO ); dst += THOM_SIZE_SYNCHRO; |
| 172 | 172 | dst += thom_floppy_make_sector( img, id, dst, sector_size ); |
| 173 | 173 | |
| 174 | | if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) ) |
| 174 | if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) ) |
| 175 | 175 | break; |
| 176 | 176 | } |
| 177 | 177 | return dst - org; |
| r29179 | r29180 | |
| 222 | 222 | |
| 223 | 223 | |
| 224 | 224 | /* build a sector, with header */ |
| 225 | | int thomson_state::thom_qdd_make_sector( device_t* img, int sector, UINT8* dst ) |
| 225 | int thomson_state::thom_qdd_make_sector( legacy_floppy_image_device* img, int sector, UINT8* dst ) |
| 226 | 226 | { |
| 227 | 227 | int i; |
| 228 | 228 | dst[ 0 ] = 0x5a; |
| 229 | | floppy_drive_read_sector_data ( img, 0, sector, dst + 1, 128 ); |
| 229 | img->floppy_drive_read_sector_data ( 0, sector, dst + 1, 128 ); |
| 230 | 230 | dst[ 129 ] = 0; |
| 231 | 231 | for ( i = 0; i < 129; i++ ) |
| 232 | 232 | dst[ 129 ] += dst[ i ]; |
| r29179 | r29180 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | 238 | /* build a whole disk */ |
| 239 | | int thomson_state::thom_qdd_make_disk ( device_t* img, UINT8* dst ) |
| 239 | int thomson_state::thom_qdd_make_disk ( legacy_floppy_image_device* img, UINT8* dst ) |
| 240 | 240 | { |
| 241 | 241 | UINT8* org = dst; |
| 242 | 242 | int i; |
| r29179 | r29180 | |
| 418 | 418 | machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | | void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state ) |
| 421 | void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,legacy_floppy_image_device *image, int state ) |
| 422 | 422 | { |
| 423 | 423 | m_mc6843->set_index_pulse( state ); |
| 424 | 424 | } |
| r29179 | r29180 | |
| 429 | 429 | LOG(( "to7_5p14sd_reset: CD 90-015 controller\n" )); |
| 430 | 430 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 431 | 431 | { |
| 432 | | device_t * img = floppy_get_device( machine(), i ); |
| 432 | legacy_floppy_image_device * img = floppy_get_device( machine(), i ); |
| 433 | 433 | if (img) { |
| 434 | | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 435 | | floppy_drive_set_rpm( img, 300. ); |
| 436 | | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
| 434 | img->floppy_drive_set_ready_state( FLOPPY_DRIVE_READY, 0 ); |
| 435 | img->floppy_drive_set_rpm( 300. ); |
| 436 | img->floppy_drive_seek( - img->floppy_drive_get_current_track() ); |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
| r29179 | r29180 | |
| 515 | 515 | |
| 516 | 516 | |
| 517 | 517 | |
| 518 | | void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state ) |
| 518 | void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,legacy_floppy_image_device *image, int state ) |
| 519 | 519 | { |
| 520 | 520 | to7qdd->index_pulse = state; |
| 521 | 521 | |
| r29179 | r29180 | |
| 532 | 532 | |
| 533 | 533 | |
| 534 | 534 | |
| 535 | | device_t * thomson_state::to7_qdd_image() |
| 535 | legacy_floppy_image_device * thomson_state::to7_qdd_image() |
| 536 | 536 | { |
| 537 | 537 | return floppy_get_device( machine(), 0 ); |
| 538 | 538 | } |
| r29179 | r29180 | |
| 548 | 548 | to7qdd->status |= QDD_S_PE; |
| 549 | 549 | |
| 550 | 550 | /* write-protect */ |
| 551 | | if (floppy_wpt_r(to7_qdd_image()) == CLEAR_LINE) |
| 551 | if (to7_qdd_image()->floppy_wpt_r() == CLEAR_LINE) |
| 552 | 552 | to7qdd->status |= QDD_S_NCTS; |
| 553 | 553 | |
| 554 | 554 | /* sticky reset conditions */ |
| r29179 | r29180 | |
| 644 | 644 | LOG(( "%f $%04x to7_qdd_write_byte: got id field for sector=%i\n", |
| 645 | 645 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 646 | 646 | |
| 647 | | floppy_drive_format_sector( to7_qdd_image(), |
| 647 | to7_qdd_image()->floppy_drive_format_sector( |
| 648 | 648 | 0, sector, 0, 0, sector, 128, filler ); |
| 649 | 649 | thom_floppy_active( 1 ); |
| 650 | 650 | to7qdd->start_idx = to7qdd->data_idx; |
| r29179 | r29180 | |
| 673 | 673 | LOG(( "%f $%04x to7_qdd_write_byte: goto data field for sector=%i\n", |
| 674 | 674 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 675 | 675 | |
| 676 | | floppy_drive_write_sector_data( to7_qdd_image(), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 ); |
| 676 | to7_qdd_image()->floppy_drive_write_sector_data( 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 ); |
| 677 | 677 | thom_floppy_active( 1 ); |
| 678 | 678 | } |
| 679 | 679 | |
| r29179 | r29180 | |
| 825 | 825 | |
| 826 | 826 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 827 | 827 | { |
| 828 | | device_t * img = floppy_get_device( machine(), i ); |
| 828 | legacy_floppy_image_device * img = floppy_get_device( machine(), i ); |
| 829 | 829 | if (img) { |
| 830 | | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 830 | img->floppy_drive_set_ready_state( FLOPPY_DRIVE_READY, 0 ); |
| 831 | 831 | |
| 832 | 832 | motor_on = CLEAR_LINE; |
| 833 | | floppy_mon_w(img, motor_on); |
| 833 | img->floppy_mon_w( motor_on); |
| 834 | 834 | |
| 835 | 835 | /* pulse each time the whole-disk spiraling track ends */ |
| 836 | 836 | /* at 90us per byte read, the disk can be read in 6s */ |
| 837 | | floppy_drive_set_rpm( img, 60. / 6. ); |
| 837 | img->floppy_drive_set_rpm( 60. / 6. ); |
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | |
| r29179 | r29180 | |
| 927 | 927 | |
| 928 | 928 | |
| 929 | 929 | |
| 930 | | device_t * thomson_state::thmfc_floppy_image() |
| 930 | legacy_floppy_image_device * thomson_state::thmfc_floppy_image() |
| 931 | 931 | { |
| 932 | 932 | return floppy_get_device( machine(), thmfc1->drive ); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | |
| 936 | 936 | |
| 937 | | int thomson_state::thmfc_floppy_is_qdd ( device_image_interface *image ) |
| 937 | int thomson_state::thmfc_floppy_is_qdd ( legacy_floppy_image_device *image ) |
| 938 | 938 | { |
| 939 | 939 | if (image==NULL) return 0; |
| 940 | 940 | if (!image->exists()) return 0; |
| r29179 | r29180 | |
| 943 | 943 | |
| 944 | 944 | |
| 945 | 945 | |
| 946 | | void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state ) |
| 946 | void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,legacy_floppy_image_device *image, int state ) |
| 947 | 947 | { |
| 948 | 948 | if ( image != thmfc_floppy_image()) |
| 949 | 949 | return; |
| 950 | 950 | |
| 951 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(image))) |
| 951 | if ( thmfc_floppy_is_qdd(image)) |
| 952 | 952 | { |
| 953 | 953 | /* pulse each time the whole-disk spiraling track ends */ |
| 954 | | floppy_drive_set_rpm( image, 16.92f /* 423/25 */ ); |
| 954 | image->floppy_drive_set_rpm( 16.92f /* 423/25 */ ); |
| 955 | 955 | thmfc1->ipl = state; |
| 956 | 956 | if ( state ) |
| 957 | 957 | { |
| r29179 | r29180 | |
| 962 | 962 | } |
| 963 | 963 | else |
| 964 | 964 | { |
| 965 | | floppy_drive_set_rpm( image, 300. ); |
| 965 | image->floppy_drive_set_rpm( 300. ); |
| 966 | 966 | thmfc1->ipl = state; |
| 967 | 967 | if ( state ) |
| 968 | 968 | thmfc1->data_raw_idx = 0; |
| r29179 | r29180 | |
| 975 | 975 | |
| 976 | 976 | int thomson_state::thmfc_floppy_find_sector( chrn_id* dst ) |
| 977 | 977 | { |
| 978 | | device_t* img = thmfc_floppy_image(); |
| 978 | legacy_floppy_image_device* img = thmfc_floppy_image(); |
| 979 | 979 | chrn_id id; |
| 980 | 980 | int r = 0; |
| 981 | 981 | |
| 982 | 982 | /* scan track, try 4 revolutions */ |
| 983 | 983 | while ( r < 4 ) |
| 984 | 984 | { |
| 985 | | if ( floppy_drive_get_next_id( img, thmfc1->side, &id ) ) |
| 985 | if ( img->floppy_drive_get_next_id( thmfc1->side, &id ) ) |
| 986 | 986 | { |
| 987 | 987 | if ( id.C == thmfc1->track && |
| 988 | 988 | id.R == thmfc1->sector && |
| r29179 | r29180 | |
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | | if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) ) |
| 1000 | if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) ) |
| 1001 | 1001 | r++; |
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | thmfc1->stat0 = THMFC1_STAT0_CRC_ERROR | THMFC1_STAT0_FINISHED; |
| 1005 | | LOG (( "thmfc_floppy_find_sector: sector not found drive=%i track=%i sector=%i\n", floppy_get_drive( img ), thmfc1->track, thmfc1->sector )); |
| 1005 | LOG (( "thmfc_floppy_find_sector: sector not found drive=%i track=%i sector=%i\n", floppy_get_drive(img), thmfc1->track, thmfc1->sector )); |
| 1006 | 1006 | return 0; |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| r29179 | r29180 | |
| 1017 | 1017 | |
| 1018 | 1018 | if ( thmfc1->op == THMFC1_OP_WRITE_SECT ) |
| 1019 | 1019 | { |
| 1020 | | device_t * img = thmfc_floppy_image(); |
| 1021 | | floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 ); |
| 1020 | legacy_floppy_image_device * img = thmfc_floppy_image(); |
| 1021 | img->floppy_drive_write_sector_data( thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 ); |
| 1022 | 1022 | thom_floppy_active( 1 ); |
| 1023 | 1023 | } |
| 1024 | 1024 | thmfc1->op = THMFC1_OP_RESET; |
| r29179 | r29180 | |
| 1068 | 1068 | /* rebuild track if needed */ |
| 1069 | 1069 | if ( ! thmfc1->data_raw_size ) |
| 1070 | 1070 | { |
| 1071 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()))) |
| 1071 | if ( thmfc_floppy_is_qdd(thmfc_floppy_image())) |
| 1072 | 1072 | /* QDD: track = whole disk */ |
| 1073 | 1073 | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data ); |
| 1074 | 1074 | else |
| r29179 | r29180 | |
| 1136 | 1136 | |
| 1137 | 1137 | LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine().time().as_double(), m_maincpu->pc(), sector )); |
| 1138 | 1138 | |
| 1139 | | floppy_drive_format_sector( thmfc_floppy_image(), 0, sector, 0, 0, sector, 128, filler ); |
| 1139 | thmfc_floppy_image()->floppy_drive_format_sector( 0, sector, 0, 0, sector, 128, filler ); |
| 1140 | 1140 | thom_floppy_active( 1 ); |
| 1141 | 1141 | thmfc1->data_idx = 0; |
| 1142 | 1142 | } |
| r29179 | r29180 | |
| 1158 | 1158 | if ( i >= 0 ) |
| 1159 | 1159 | { |
| 1160 | 1160 | /* got an id & a data field => write */ |
| 1161 | | device_t * img = thmfc_floppy_image(); |
| 1161 | legacy_floppy_image_device * img = thmfc_floppy_image(); |
| 1162 | 1162 | int sector = (int) thmfc1->data[ i + 1 ] * 256 + |
| 1163 | 1163 | (int) thmfc1->data[ i + 2 ]; |
| 1164 | 1164 | |
| 1165 | 1165 | LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: data field, sector=%i\n", |
| 1166 | 1166 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 1167 | 1167 | |
| 1168 | | floppy_drive_write_sector_data( img, 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 ); |
| 1168 | img->floppy_drive_write_sector_data( 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 ); |
| 1169 | 1169 | thom_floppy_active( 1 ); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| r29179 | r29180 | |
| 1218 | 1218 | if ( !memcmp ( thmfc1->data, header, sizeof( header ) ) ) |
| 1219 | 1219 | { |
| 1220 | 1220 | /* got id field => format */ |
| 1221 | | device_t * img = thmfc_floppy_image(); |
| 1221 | legacy_floppy_image_device * img = thmfc_floppy_image(); |
| 1222 | 1222 | UINT8 track = thmfc1->data[4]; |
| 1223 | 1223 | UINT8 side = thmfc1->data[5]; |
| 1224 | 1224 | UINT8 sector = thmfc1->data[6]; |
| r29179 | r29180 | |
| 1227 | 1227 | chrn_id id; |
| 1228 | 1228 | if ( thmfc_floppy_find_sector( &id ) ) |
| 1229 | 1229 | { |
| 1230 | | floppy_drive_format_sector( img, side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler ); |
| 1230 | img->floppy_drive_format_sector( side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler ); |
| 1231 | 1231 | thom_floppy_active( 1 ); |
| 1232 | 1232 | } |
| 1233 | 1233 | } |
| r29179 | r29180 | |
| 1252 | 1252 | case 1: /* STAT1 */ |
| 1253 | 1253 | { |
| 1254 | 1254 | UINT8 data = 0; |
| 1255 | | device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image()); |
| 1256 | | int flags = floppy_drive_get_flag_state( &img->device(), -1 ); |
| 1255 | legacy_floppy_image_device * img = thmfc_floppy_image(); |
| 1256 | int flags = img->floppy_drive_get_flag_state(-1 ); |
| 1257 | 1257 | if ( thmfc_floppy_is_qdd(img) ) |
| 1258 | 1258 | { |
| 1259 | 1259 | if ( ! img->exists() ) |
| r29179 | r29180 | |
| 1269 | 1269 | if ( img->exists() ) |
| 1270 | 1270 | data |= 0x20; /* disk change (?) */ |
| 1271 | 1271 | |
| 1272 | | data |= !floppy_tk00_r(&img->device()) << 3; |
| 1272 | data |= !img->floppy_tk00_r() << 3; |
| 1273 | 1273 | |
| 1274 | 1274 | if ( flags & FLOPPY_DRIVE_READY ) |
| 1275 | 1275 | data |= 0x02; |
| 1276 | 1276 | } |
| 1277 | 1277 | if (!motor_on) |
| 1278 | 1278 | data |= 0x10; |
| 1279 | | if (!floppy_wpt_r(&img->device())) |
| 1279 | if (!img->floppy_wpt_r()) |
| 1280 | 1280 | data |= 0x04; |
| 1281 | 1281 | VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 1282 | 1282 | return data; |
| r29179 | r29180 | |
| 1314 | 1314 | case 0: /* CMD0 */ |
| 1315 | 1315 | { |
| 1316 | 1316 | int wsync = (data >> 4) & 1; |
| 1317 | | int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())); |
| 1317 | int qdd = thmfc_floppy_is_qdd(thmfc_floppy_image()); |
| 1318 | 1318 | chrn_id id; |
| 1319 | 1319 | thmfc1->formatting = (data >> 2) & 1; |
| 1320 | 1320 | LOG (( "%f $%04x thmfc_floppy_w: CMD0=$%02X dens=%s wsync=%i dsync=%i fmt=%i op=%i\n", |
| r29179 | r29180 | |
| 1415 | 1415 | |
| 1416 | 1416 | case 2: /* CMD2 */ |
| 1417 | 1417 | { |
| 1418 | | device_t * img; |
| 1418 | legacy_floppy_image_device * img; |
| 1419 | 1419 | int seek = 0, motor; |
| 1420 | 1420 | thmfc1->drive = data & 2; |
| 1421 | 1421 | |
| 1422 | | img = thmfc_floppy_image(); |
| 1423 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(img))) |
| 1422 | img = thmfc_floppy_image(); |
| 1423 | if ( thmfc_floppy_is_qdd(img)) |
| 1424 | 1424 | { |
| 1425 | 1425 | motor = !(data & 0x40); |
| 1426 | 1426 | /* no side select & no seek for QDD */ |
| r29179 | r29180 | |
| 1443 | 1443 | if ( seek ) |
| 1444 | 1444 | { |
| 1445 | 1445 | thmfc1->data_raw_size = 0; |
| 1446 | | floppy_drive_seek( img, seek ); |
| 1446 | img->floppy_drive_seek( seek ); |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /* in real life, to keep the motor running, it is sufficient to |
| r29179 | r29180 | |
| 1451 | 1451 | instead of counting, we assume the motor is always running... |
| 1452 | 1452 | */ |
| 1453 | 1453 | motor_on = CLEAR_LINE /* motor */; |
| 1454 | | floppy_mon_w(img, motor_on); |
| 1454 | img->floppy_mon_w(motor_on); |
| 1455 | 1455 | } |
| 1456 | 1456 | break; |
| 1457 | 1457 | |
| 1458 | 1458 | |
| 1459 | 1459 | case 3: /* WDATA */ |
| 1460 | 1460 | thmfc1->wsync = data; |
| 1461 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()))) |
| 1461 | if ( thmfc_floppy_is_qdd(thmfc_floppy_image())) |
| 1462 | 1462 | thmfc_floppy_qdd_write_byte( data ); |
| 1463 | 1463 | else if ( thmfc1->op==THMFC1_OP_WRITE_SECT ) |
| 1464 | 1464 | thmfc_floppy_write_byte( data ); |
| r29179 | r29180 | |
| 1490 | 1490 | thmfc1->track = data; |
| 1491 | 1491 | LOG (( "%f $%04x thmfc_floppy_w: WTRCK=%i (real=%i)\n", |
| 1492 | 1492 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1493 | | floppy_drive_get_current_track( thmfc_floppy_image() ) )); |
| 1493 | thmfc_floppy_image()->floppy_drive_get_current_track())); |
| 1494 | 1494 | break; |
| 1495 | 1495 | |
| 1496 | 1496 | case 7: /* WCELL */ |
| r29179 | r29180 | |
| 1514 | 1514 | |
| 1515 | 1515 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 1516 | 1516 | { |
| 1517 | | device_t * img = floppy_get_device( machine(), i ); |
| 1517 | legacy_floppy_image_device * img = floppy_get_device( machine(), i ); |
| 1518 | 1518 | if (img) { |
| 1519 | | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 1520 | | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
| 1519 | img->floppy_drive_set_ready_state( FLOPPY_DRIVE_READY, 0 ); |
| 1520 | img->floppy_drive_seek( - img->floppy_drive_get_current_track() ); |
| 1521 | 1521 | } |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| r29179 | r29180 | |
| 1912 | 1912 | to7_5p14_w( space, offset, data, mem_mask ); |
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | | void thomson_state::thomson_index_callback(device_t *device, int state) |
| 1915 | void thomson_state::thomson_index_callback(legacy_floppy_image_device *device, int state) |
| 1916 | 1916 | { |
| 1917 | 1917 | switch ( to7_controller_type ) |
| 1918 | 1918 | { |
trunk/src/emu/machine/wd17xx.c
| r29179 | r29180 | |
| 154 | 154 | #include "emu.h" |
| 155 | 155 | #include "formats/imageutl.h" |
| 156 | 156 | #include "machine/wd17xx.h" |
| 157 | | #include "imagedev/flopdrv.h" |
| 158 | 157 | |
| 159 | 158 | /*************************************************************************** |
| 160 | 159 | CONSTANTS |
| r29179 | r29180 | |
| 494 | 493 | if (1) // image_slotexists(m_drive) : FIXME |
| 495 | 494 | { |
| 496 | 495 | /* keep stepping until track 0 is received or 255 steps have been done */ |
| 497 | | while (floppy_tk00_r(m_drive) && (step_counter != 0)) |
| 496 | while (m_drive->floppy_tk00_r() && (step_counter != 0)) |
| 498 | 497 | { |
| 499 | 498 | /* update time to simulate seek time busy signal */ |
| 500 | 499 | m_busy_count++; |
| 501 | | floppy_drive_seek(m_drive, m_direction); |
| 500 | m_drive->floppy_drive_seek(m_direction); |
| 502 | 501 | step_counter--; |
| 503 | 502 | } |
| 504 | 503 | } |
| r29179 | r29180 | |
| 539 | 538 | //int len = m_buffer[i+4]; |
| 540 | 539 | int filler = 0xe5; /* IBM and Thomson */ |
| 541 | 540 | int density = m_density; |
| 542 | | floppy_drive_format_sector(m_drive,side,sector,track, |
| 541 | m_drive->floppy_drive_format_sector(side,sector,track, |
| 543 | 542 | m_hd,sector,density?1:0,filler); |
| 544 | 543 | i += 128; /* at least... */ |
| 545 | 544 | } |
| r29179 | r29180 | |
| 556 | 555 | selected format. |
| 557 | 556 | */ |
| 558 | 557 | m_data_count = 0; |
| 559 | | floppy = flopimg_get_image(m_drive); |
| 558 | floppy = m_drive->flopimg_get_image(); |
| 560 | 559 | if (floppy != NULL) |
| 561 | 560 | m_data_count = floppy_get_track_size(floppy, m_hd, m_track); |
| 562 | 561 | |
| r29179 | r29180 | |
| 568 | 567 | m_data_count = wd17xx_dden() ? TRKSIZE_SD : TRKSIZE_DD; |
| 569 | 568 | } |
| 570 | 569 | |
| 571 | | floppy_drive_write_track_data_info_buffer( m_drive, m_hd, (char *)m_buffer, &(m_data_count) ); |
| 570 | m_drive->floppy_drive_write_track_data_info_buffer( m_hd, (char *)m_buffer, &(m_data_count) ); |
| 572 | 571 | |
| 573 | 572 | m_data_offset = 0; |
| 574 | 573 | |
| r29179 | r29180 | |
| 707 | 706 | /* Determine the track size. We cannot allow different sizes in this |
| 708 | 707 | design (see above, write_track). */ |
| 709 | 708 | m_data_count = 0; |
| 710 | | floppy = flopimg_get_image(m_drive); |
| 709 | floppy = m_drive->flopimg_get_image(); |
| 711 | 710 | if (floppy != NULL) |
| 712 | 711 | m_data_count = floppy_get_track_size(floppy, m_hd, m_track); |
| 713 | 712 | |
| r29179 | r29180 | |
| 719 | 718 | m_data_count = wd17xx_dden() ? TRKSIZE_SD : TRKSIZE_DD; |
| 720 | 719 | } |
| 721 | 720 | |
| 722 | | floppy_drive_read_track_data_info_buffer( m_drive, m_hd, (char *)m_buffer, &(m_data_count) ); |
| 721 | m_drive->floppy_drive_read_track_data_info_buffer( m_hd, (char *)m_buffer, &(m_data_count) ); |
| 723 | 722 | |
| 724 | 723 | m_data_offset = 0; |
| 725 | 724 | |
| r29179 | r29180 | |
| 736 | 735 | m_status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND); |
| 737 | 736 | |
| 738 | 737 | /* get next id from disc */ |
| 739 | | if (floppy_drive_get_next_id(m_drive, m_hd, &id)) |
| 738 | if (m_drive->floppy_drive_get_next_id(m_hd, &id)) |
| 740 | 739 | { |
| 741 | 740 | UINT16 crc = 0xffff; |
| 742 | 741 | |
| r29179 | r29180 | |
| 809 | 808 | |
| 810 | 809 | while (revolution_count!=4) |
| 811 | 810 | { |
| 812 | | if (floppy_drive_get_next_id(m_drive, m_hd, &id)) |
| 811 | if (m_drive->floppy_drive_get_next_id(m_hd, &id)) |
| 813 | 812 | { |
| 814 | 813 | /* compare track */ |
| 815 | 814 | if (id.C == m_track) |
| r29179 | r29180 | |
| 834 | 833 | } |
| 835 | 834 | |
| 836 | 835 | /* index set? */ |
| 837 | | if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_INDEX)) |
| 836 | if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX)) |
| 838 | 837 | { |
| 839 | 838 | /* update revolution count */ |
| 840 | 839 | revolution_count++; |
| r29179 | r29180 | |
| 886 | 885 | m_data_count = m_sector_length; |
| 887 | 886 | |
| 888 | 887 | /* read data */ |
| 889 | | floppy_drive_read_sector_data(m_drive, m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length); |
| 888 | m_drive->floppy_drive_read_sector_data(m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length); |
| 890 | 889 | |
| 891 | 890 | wd17xx_timed_data_request(); |
| 892 | 891 | |
| r29179 | r29180 | |
| 936 | 935 | m_data_count = m_sector_length; |
| 937 | 936 | |
| 938 | 937 | /* write data */ |
| 939 | | floppy_drive_write_sector_data(m_drive, m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01); |
| 938 | m_drive->floppy_drive_write_sector_data(m_hd, m_sector_data_id, (char *)m_buffer, m_sector_length, m_write_cmd & 0x01); |
| 940 | 939 | } |
| 941 | 940 | } |
| 942 | 941 | |
| r29179 | r29180 | |
| 957 | 956 | /* must be found within 5 revolutions otherwise error */ |
| 958 | 957 | while (revolution_count!=5) |
| 959 | 958 | { |
| 960 | | if (floppy_drive_get_next_id(m_drive, m_hd, &id)) |
| 959 | if (m_drive->floppy_drive_get_next_id( m_hd, &id)) |
| 961 | 960 | { |
| 962 | 961 | /* compare track */ |
| 963 | 962 | if (id.C == m_track) |
| r29179 | r29180 | |
| 969 | 968 | } |
| 970 | 969 | |
| 971 | 970 | /* index set? */ |
| 972 | | if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_INDEX)) |
| 971 | if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX)) |
| 973 | 972 | { |
| 974 | 973 | /* update revolution count */ |
| 975 | 974 | revolution_count++; |
| r29179 | r29180 | |
| 992 | 991 | if (VERBOSE) |
| 993 | 992 | logerror("wd179x: Read Sector callback.\n"); |
| 994 | 993 | |
| 995 | | if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY)) |
| 994 | if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 996 | 995 | wd17xx_complete_command(DELAY_NOTREADY); |
| 997 | 996 | else |
| 998 | 997 | wd17xx_read_sector(); |
| r29179 | r29180 | |
| 1008 | 1007 | if (VERBOSE) |
| 1009 | 1008 | logerror("wd179x: Write Sector callback.\n"); |
| 1010 | 1009 | |
| 1011 | | if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY)) |
| 1010 | if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1012 | 1011 | wd17xx_complete_command(DELAY_NOTREADY); |
| 1013 | 1012 | else |
| 1014 | 1013 | { |
| 1015 | 1014 | /* drive write protected? */ |
| 1016 | | if (floppy_wpt_r(m_drive) == CLEAR_LINE) |
| 1015 | if (m_drive->floppy_wpt_r() == CLEAR_LINE) |
| 1017 | 1016 | { |
| 1018 | 1017 | m_status |= STA_2_WRITE_PRO; |
| 1019 | 1018 | |
| r29179 | r29180 | |
| 1080 | 1079 | |
| 1081 | 1080 | if (m_intf->floppy_drive_tags[drive] != NULL) |
| 1082 | 1081 | { |
| 1083 | | m_drive = siblingdevice(m_intf->floppy_drive_tags[drive]); |
| 1082 | m_drive = siblingdevice<legacy_floppy_image_device>(m_intf->floppy_drive_tags[drive]); |
| 1084 | 1083 | } |
| 1085 | 1084 | } |
| 1086 | 1085 | |
| r29179 | r29180 | |
| 1201 | 1200 | else |
| 1202 | 1201 | { |
| 1203 | 1202 | m_status &= ~STA_1_NOT_READY; |
| 1204 | | if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY)) |
| 1203 | if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1205 | 1204 | m_status |= STA_1_NOT_READY; |
| 1206 | 1205 | } |
| 1207 | 1206 | |
| r29179 | r29180 | |
| 1216 | 1215 | result |= m_idx << 1; |
| 1217 | 1216 | |
| 1218 | 1217 | /* bit 2, track 0 state, inverted */ |
| 1219 | | result |= !floppy_tk00_r(m_drive) << 2; |
| 1218 | result |= !m_drive->floppy_tk00_r() << 2; |
| 1220 | 1219 | |
| 1221 | 1220 | if (m_command_type==TYPE_I) |
| 1222 | 1221 | { |
| r29179 | r29180 | |
| 1227 | 1226 | } |
| 1228 | 1227 | |
| 1229 | 1228 | /* bit 6, write protect, inverted */ |
| 1230 | | result |= !floppy_wpt_r(m_drive) << 6; |
| 1229 | result |= !m_drive->floppy_wpt_r() << 6; |
| 1231 | 1230 | } |
| 1232 | 1231 | |
| 1233 | 1232 | /* eventually set data request bit */ |
| r29179 | r29180 | |
| 1283 | 1282 | if (type() == WD1770 || type() == WD1772) |
| 1284 | 1283 | { |
| 1285 | 1284 | m_mo = ASSERT_LINE; |
| 1286 | | floppy_mon_w(m_drive, CLEAR_LINE); |
| 1285 | m_drive->floppy_mon_w(CLEAR_LINE); |
| 1287 | 1286 | } |
| 1288 | 1287 | |
| 1289 | | floppy_drive_set_ready_state(m_drive, 1,0); |
| 1288 | m_drive->floppy_drive_set_ready_state(1,0); |
| 1290 | 1289 | |
| 1291 | 1290 | if (!BIT(m_interrupt, 3)) |
| 1292 | 1291 | { |
| r29179 | r29180 | |
| 1409 | 1408 | m_status &= ~STA_2_LOST_DAT; |
| 1410 | 1409 | wd17xx_clear_drq(); |
| 1411 | 1410 | |
| 1412 | | if (!floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY)) |
| 1411 | if (!m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1413 | 1412 | { |
| 1414 | 1413 | wd17xx_complete_command(DELAY_NOTREADY); |
| 1415 | 1414 | } |
| 1416 | 1415 | else |
| 1417 | 1416 | { |
| 1418 | 1417 | /* drive write protected? */ |
| 1419 | | if (floppy_wpt_r(m_drive) == CLEAR_LINE) |
| 1418 | if (m_drive->floppy_wpt_r() == CLEAR_LINE) |
| 1420 | 1419 | { |
| 1421 | 1420 | /* yes */ |
| 1422 | 1421 | m_status |= STA_2_WRITE_PRO; |
| r29179 | r29180 | |
| 1452 | 1451 | |
| 1453 | 1452 | wd17xx_clear_drq(); |
| 1454 | 1453 | |
| 1455 | | if (floppy_drive_get_flag_state(m_drive, FLOPPY_DRIVE_READY)) |
| 1454 | if (m_drive->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1456 | 1455 | wd17xx_read_id(); |
| 1457 | 1456 | else |
| 1458 | 1457 | wd17xx_complete_command(DELAY_NOTREADY); |
| r29179 | r29180 | |
| 1519 | 1518 | /* update track reg */ |
| 1520 | 1519 | m_track += m_direction; |
| 1521 | 1520 | |
| 1522 | | floppy_drive_seek(m_drive, m_direction); |
| 1521 | m_drive->floppy_drive_seek(m_direction); |
| 1523 | 1522 | } |
| 1524 | 1523 | |
| 1525 | 1524 | /* simulate seek time busy signal */ |
| r29179 | r29180 | |
| 1541 | 1540 | /* simulate seek time busy signal */ |
| 1542 | 1541 | m_busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1543 | 1542 | |
| 1544 | | floppy_drive_seek(m_drive, m_direction); |
| 1543 | m_drive->floppy_drive_seek(m_direction); |
| 1545 | 1544 | |
| 1546 | 1545 | if (data & FDC_STEP_UPDATE) |
| 1547 | 1546 | m_track += m_direction; |
| r29179 | r29180 | |
| 1564 | 1563 | /* simulate seek time busy signal */ |
| 1565 | 1564 | m_busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1566 | 1565 | |
| 1567 | | floppy_drive_seek(m_drive, m_direction); |
| 1566 | m_drive->floppy_drive_seek(m_direction); |
| 1568 | 1567 | |
| 1569 | 1568 | if (data & FDC_STEP_UPDATE) |
| 1570 | 1569 | m_track += m_direction; |
| r29179 | r29180 | |
| 1586 | 1585 | m_busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1587 | 1586 | |
| 1588 | 1587 | /* for now only allows a single drive to be selected */ |
| 1589 | | floppy_drive_seek(m_drive, m_direction); |
| 1588 | m_drive->floppy_drive_seek(m_direction); |
| 1590 | 1589 | |
| 1591 | 1590 | if (data & FDC_STEP_UPDATE) |
| 1592 | 1591 | m_track += m_direction; |
| r29179 | r29180 | |
| 2045 | 2044 | for (i = 0; i < 4; i++) |
| 2046 | 2045 | { |
| 2047 | 2046 | if(m_intf->floppy_drive_tags[i]!=NULL) { |
| 2048 | | device_t *img = NULL; |
| 2047 | legacy_floppy_image_device *img = NULL; |
| 2049 | 2048 | |
| 2050 | | img = siblingdevice(m_intf->floppy_drive_tags[i]); |
| 2049 | img = siblingdevice<legacy_floppy_image_device>(m_intf->floppy_drive_tags[i]); |
| 2051 | 2050 | |
| 2052 | 2051 | if (img!=NULL) { |
| 2053 | | floppy_drive_set_controller(img,this); |
| 2054 | | floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback); |
| 2055 | | floppy_drive_set_rpm( img, 300.); |
| 2052 | img->floppy_drive_set_controller(this); |
| 2053 | img->floppy_drive_set_index_pulse_callback(wd17xx_index_pulse_callback); |
| 2054 | img->floppy_drive_set_rpm( 300.); |
| 2056 | 2055 | } |
| 2057 | 2056 | } |
| 2058 | 2057 | } |
trunk/src/emu/machine/smc92x4.c
| r29179 | r29180 | |
| 200 | 200 | |
| 201 | 201 | int smc92x4_device::image_is_single_density() |
| 202 | 202 | { |
| 203 | | floppy_image_legacy *image = flopimg_get_image(m_drive); |
| 203 | floppy_image_legacy *image = m_drive->flopimg_get_image(); |
| 204 | 204 | return (floppy_get_track_size(image, 0, 0)<4000); |
| 205 | 205 | } |
| 206 | 206 | |
| r29179 | r29180 | |
| 436 | 436 | int redcur; |
| 437 | 437 | int precomp; |
| 438 | 438 | int write_long; |
| 439 | | mfm_harddisk_device *harddisk; |
| 440 | 439 | |
| 441 | 440 | switch (id) |
| 442 | 441 | { |
| r29179 | r29180 | |
| 481 | 480 | else |
| 482 | 481 | { |
| 483 | 482 | if (VERBOSE>5) LOG("smc92x4 step %s direction %d\n", m_drive->tag(), m_step_direction); |
| 484 | | floppy_drive_seek(m_drive, m_step_direction); |
| 483 | m_drive->floppy_drive_seek(m_step_direction); |
| 485 | 484 | } |
| 486 | 485 | } |
| 487 | 486 | else |
| 488 | 487 | { |
| 489 | 488 | if (VERBOSE>6) LOG("smc92x4 step harddisk direction %d\n", m_step_direction); |
| 490 | | harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 491 | | harddisk->seek(m_step_direction); |
| 489 | m_harddisk->seek(m_step_direction); |
| 492 | 490 | } |
| 493 | 491 | sync_status_in(); |
| 494 | 492 | break; |
| r29179 | r29180 | |
| 566 | 564 | { |
| 567 | 565 | int des_cylinder, cur_cylinder; |
| 568 | 566 | bool found = false; |
| 569 | | mfm_harddisk_device *harddisk; |
| 570 | 567 | |
| 571 | 568 | sync_latches_out(); |
| 572 | 569 | sync_status_in(); |
| r29179 | r29180 | |
| 579 | 576 | if (m_selected_drive_type & TYPE_FLOPPY) |
| 580 | 577 | { |
| 581 | 578 | chrn_id idflop; |
| 582 | | if (flopimg_get_image(m_drive) == NULL) |
| 579 | if (m_drive->flopimg_get_image() == NULL) |
| 583 | 580 | { |
| 584 | 581 | if (VERBOSE>2) LOG("smc92x4 warn: No disk in drive\n"); |
| 585 | 582 | m_register_r[CHIP_STATUS] |= CS_SYNCERR; |
| r29179 | r29180 | |
| 590 | 587 | if ((image_is_single_density() && in_single_density_mode()) |
| 591 | 588 | || (!image_is_single_density() && !in_single_density_mode())) |
| 592 | 589 | { |
| 593 | | found = floppy_drive_get_next_id(m_drive, m_register_w[DESIRED_HEAD]&0x0f, &idflop); |
| 590 | found = m_drive->floppy_drive_get_next_id(m_register_w[DESIRED_HEAD]&0x0f, &idflop); |
| 594 | 591 | copyid(idflop, id); /* Need to use bigger values for HD, but we don't use separate variables here */ |
| 595 | 592 | } |
| 596 | 593 | else |
| r29179 | r29180 | |
| 608 | 605 | } |
| 609 | 606 | else |
| 610 | 607 | { |
| 611 | | harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 612 | | |
| 613 | | harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id); |
| 608 | m_harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id); |
| 614 | 609 | sync_status_in(); |
| 615 | 610 | if (!(m_register_r[DRIVE_STATUS]& DS_READY)) |
| 616 | 611 | { |
| r29179 | r29180 | |
| 670 | 665 | int found = false; |
| 671 | 666 | int foundsect = false; |
| 672 | 667 | int des_cylinder = 0; |
| 673 | | mfm_harddisk_device *harddisk; |
| 674 | 668 | |
| 675 | 669 | // Set command termination code. The error code is set first, and |
| 676 | 670 | // on success, it is cleared. |
| r29179 | r29180 | |
| 683 | 677 | if (m_selected_drive_type & TYPE_FLOPPY) |
| 684 | 678 | { |
| 685 | 679 | chrn_id idflop; |
| 686 | | found = floppy_drive_get_next_id(m_drive, m_register_w[DESIRED_HEAD]&0x0f, &idflop); |
| 680 | found = m_drive->floppy_drive_get_next_id(m_register_w[DESIRED_HEAD]&0x0f, &idflop); |
| 687 | 681 | copyid(idflop, id); |
| 688 | 682 | if (/* pass==1 && */!found) |
| 689 | 683 | { |
| r29179 | r29180 | |
| 694 | 688 | } |
| 695 | 689 | else |
| 696 | 690 | { |
| 697 | | harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 698 | | harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id); |
| 691 | m_harddisk->get_next_id(m_register_w[DESIRED_HEAD]&0x0f, id); |
| 699 | 692 | sync_status_in(); |
| 700 | 693 | if (!(m_register_r[DRIVE_STATUS]& DS_READY)) |
| 701 | 694 | { |
| r29179 | r29180 | |
| 742 | 735 | void smc92x4_device::data_transfer_read(chrn_id_hd id, int transfer_enable) |
| 743 | 736 | { |
| 744 | 737 | int i, retry, sector_len; |
| 745 | | mfm_harddisk_device *harddisk; |
| 746 | 738 | |
| 747 | 739 | int sector_data_id; |
| 748 | 740 | dynamic_buffer buf; |
| r29179 | r29180 | |
| 780 | 772 | |
| 781 | 773 | if (m_selected_drive_type & TYPE_FLOPPY) |
| 782 | 774 | { |
| 783 | | floppy_drive_read_sector_data(m_drive, id.H, sector_data_id, buf, sector_len); |
| 775 | m_drive->floppy_drive_read_sector_data(id.H, sector_data_id, buf, sector_len); |
| 784 | 776 | } |
| 785 | 777 | else |
| 786 | 778 | { |
| 787 | 779 | // TODO: Should we get the sector length from the harddisk? |
| 788 | | harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 789 | | harddisk->read_sector(id.C, id.H, id.R, buf); |
| 780 | m_harddisk->read_sector(id.C, id.H, id.R, buf); |
| 790 | 781 | } |
| 791 | 782 | sync_status_in(); |
| 792 | 783 | |
| r29179 | r29180 | |
| 837 | 828 | int retry, i, sector_len; |
| 838 | 829 | dynamic_buffer buf; |
| 839 | 830 | int sector_data_id; |
| 840 | | mfm_harddisk_device *harddisk; |
| 841 | 831 | sync_latches_out(); |
| 842 | 832 | sync_status_in(); |
| 843 | 833 | |
| r29179 | r29180 | |
| 876 | 866 | if (m_selected_drive_type & TYPE_FLOPPY) |
| 877 | 867 | { |
| 878 | 868 | if (VERBOSE>4) LOG("smc92x4 info: write sector CHS=(%d,%d,%d)\n", id.C, id.H, id.R); |
| 879 | | floppy_drive_write_sector_data(m_drive, id.H, sector_data_id, buf, sector_len, false); |
| 869 | m_drive->floppy_drive_write_sector_data(id.H, sector_data_id, buf, sector_len, false); |
| 880 | 870 | } |
| 881 | 871 | else |
| 882 | 872 | { |
| 883 | | harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 884 | | harddisk->write_sector(id.C, id.H, id.R, buf); |
| 873 | m_harddisk->write_sector(id.C, id.H, id.R, buf); |
| 885 | 874 | } |
| 886 | 875 | sync_status_in(); |
| 887 | 876 | |
| r29179 | r29180 | |
| 1344 | 1333 | |
| 1345 | 1334 | sync_status_in(); |
| 1346 | 1335 | |
| 1347 | | floppy = flopimg_get_image(m_drive); |
| 1336 | floppy = m_drive->flopimg_get_image(); |
| 1348 | 1337 | |
| 1349 | 1338 | if (floppy != NULL) |
| 1350 | 1339 | data_count = floppy_get_track_size(floppy, 0, 0); |
| r29179 | r29180 | |
| 1486 | 1475 | memset(&buffer[index], gap_byte, gap4); |
| 1487 | 1476 | index += gap4; |
| 1488 | 1477 | |
| 1489 | | floppy_drive_write_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, buffer, &data_count); |
| 1478 | m_drive->floppy_drive_write_track_data_info_buffer(m_register_w[DESIRED_HEAD]&0x0f, buffer, &data_count); |
| 1490 | 1479 | sync_status_in(); |
| 1491 | 1480 | } |
| 1492 | 1481 | |
| r29179 | r29180 | |
| 1506 | 1495 | int normal_data_mark = flags & 0x10; |
| 1507 | 1496 | int data_count=0; |
| 1508 | 1497 | |
| 1509 | | mfm_harddisk_device *harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 1510 | | |
| 1511 | 1498 | dynamic_buffer buffer; |
| 1512 | 1499 | |
| 1513 | 1500 | sync_status_in(); |
| r29179 | r29180 | |
| 1585 | 1572 | for (i=0; i < gap4; i++) buffer[index++] = gap_byte; |
| 1586 | 1573 | |
| 1587 | 1574 | // Now write the whole track |
| 1588 | | harddisk->write_track(m_register_w[DESIRED_HEAD]&0x0f, buffer, data_count); |
| 1575 | m_harddisk->write_track(m_register_w[DESIRED_HEAD]&0x0f, buffer, data_count); |
| 1589 | 1576 | |
| 1590 | 1577 | sync_status_in(); |
| 1591 | 1578 | } |
| r29179 | r29180 | |
| 1618 | 1605 | |
| 1619 | 1606 | sync_latches_out(); |
| 1620 | 1607 | |
| 1621 | | floppy = flopimg_get_image(m_drive); |
| 1608 | floppy = m_drive->flopimg_get_image(); |
| 1622 | 1609 | |
| 1623 | 1610 | /* Determine the track size. We cannot allow different sizes in this design. */ |
| 1624 | 1611 | if (floppy != NULL) |
| r29179 | r29180 | |
| 1634 | 1621 | |
| 1635 | 1622 | buffer = global_alloc_array(UINT8, data_count); |
| 1636 | 1623 | |
| 1637 | | floppy_drive_read_track_data_info_buffer(m_drive, m_register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count); |
| 1624 | m_drive->floppy_drive_read_track_data_info_buffer(m_register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count); |
| 1638 | 1625 | sync_status_in(); |
| 1639 | 1626 | |
| 1640 | 1627 | // Transfer the buffer to the external memory. We assume the memory |
| r29179 | r29180 | |
| 1662 | 1649 | int i; |
| 1663 | 1650 | UINT8 *buffer; |
| 1664 | 1651 | int data_count=0; |
| 1665 | | mfm_harddisk_device *harddisk = static_cast<mfm_harddisk_device *>(m_drive); |
| 1666 | | |
| 1667 | 1652 | sync_latches_out(); |
| 1668 | 1653 | |
| 1669 | | data_count = harddisk->get_track_length(); |
| 1654 | data_count = m_harddisk->get_track_length(); |
| 1670 | 1655 | buffer = global_alloc_array(UINT8, data_count); |
| 1671 | 1656 | |
| 1672 | 1657 | /* buffer and data_count are allocated and set by the function. */ |
| 1673 | | harddisk->read_track(m_register_w[DESIRED_HEAD]&0x0f, buffer); |
| 1658 | m_harddisk->read_track(m_register_w[DESIRED_HEAD]&0x0f, buffer); |
| 1674 | 1659 | sync_status_in(); |
| 1675 | 1660 | |
| 1676 | 1661 | if (!(m_register_r[DRIVE_STATUS] & DS_READY)) |
| r29179 | r29180 | |
| 2004 | 1989 | if (VERBOSE>0) LOG("smc92x4: use realistic timing: %02x\n", realistic); |
| 2005 | 1990 | } |
| 2006 | 1991 | |
| 2007 | | void smc92x4_device::connect_drive(device_t *drive) |
| 1992 | void smc92x4_device::connect_floppy_drive(legacy_floppy_image_device *drive) |
| 2008 | 1993 | { |
| 2009 | 1994 | m_drive = drive; |
| 2010 | 1995 | if (VERBOSE>3) |
| r29179 | r29180 | |
| 2013 | 1998 | else LOG("smc92x4: Connect drive %s\n", drive->tag()); |
| 2014 | 1999 | } |
| 2015 | 2000 | } |
| 2001 | void smc92x4_device::connect_hard_drive(mfm_harddisk_device *drive) |
| 2002 | { |
| 2003 | m_harddisk = drive; |
| 2004 | if (VERBOSE>3) |
| 2005 | { |
| 2006 | if (drive==NULL) LOG("smc92x4: Unselect all drives\n"); |
| 2007 | else LOG("smc92x4: Connect drive %s\n", drive->tag()); |
| 2008 | } |
| 2009 | } |
| 2016 | 2010 | |
| 2017 | 2011 | void smc92x4_device::reset() |
| 2018 | 2012 | { |
trunk/src/emu/machine/mc6843.c
| r29179 | r29180 | |
| 139 | 139 | /* setup/reset floppy drive */ |
| 140 | 140 | for ( i = 0; i < 4; i++ ) |
| 141 | 141 | { |
| 142 | | device_t * img = floppy_image( i ); |
| 143 | | floppy_mon_w(img, CLEAR_LINE); |
| 144 | | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 145 | | floppy_drive_set_rpm( img, 300. ); |
| 142 | legacy_floppy_image_device * img = floppy_image( i ); |
| 143 | img->floppy_mon_w(CLEAR_LINE); |
| 144 | img->floppy_drive_set_ready_state(FLOPPY_DRIVE_READY, 0 ); |
| 145 | img->floppy_drive_set_rpm( 300. ); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /* reset registers */ |
| r29179 | r29180 | |
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 | |
| 165 | | device_t* mc6843_device::floppy_image( UINT8 drive ) |
| 165 | legacy_floppy_image_device* mc6843_device::floppy_image( UINT8 drive ) |
| 166 | 166 | { |
| 167 | | device_t *img = floppy_get_device( machine(), drive ); |
| 167 | legacy_floppy_image_device *img = floppy_get_device( machine(), drive ); |
| 168 | 168 | if (!img && owner()) { |
| 169 | 169 | // For slot devices, drives are typically attached to the slot rather than the machine |
| 170 | 170 | const char *floppy_name = NULL; |
| r29179 | r29180 | |
| 182 | 182 | floppy_name = FLOPPY_3; |
| 183 | 183 | break; |
| 184 | 184 | } |
| 185 | | img = owner()->subdevice(floppy_name); |
| 185 | img = owner()->subdevice<legacy_floppy_image_device>(floppy_name); |
| 186 | 186 | } |
| 187 | 187 | return img; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
| 191 | | device_t* mc6843_device::floppy_image( ) |
| 191 | legacy_floppy_image_device* mc6843_device::floppy_image( ) |
| 192 | 192 | { |
| 193 | 193 | return floppy_image( m_drive ); |
| 194 | 194 | } |
| r29179 | r29180 | |
| 262 | 262 | /* Seek Track Zero bottom half */ |
| 263 | 263 | void mc6843_device::finish_STZ( ) |
| 264 | 264 | { |
| 265 | | device_t* img = floppy_image( ); |
| 265 | legacy_floppy_image_device* img = floppy_image( ); |
| 266 | 266 | int i; |
| 267 | 267 | |
| 268 | 268 | /* seek to track zero */ |
| 269 | 269 | for ( i=0; i<83; i++ ) |
| 270 | 270 | { |
| 271 | | if (floppy_tk00_r(img) == CLEAR_LINE) |
| 271 | if (img->floppy_tk00_r() == CLEAR_LINE) |
| 272 | 272 | break; |
| 273 | | floppy_drive_seek( img, -1 ); |
| 273 | img->floppy_drive_seek( -1 ); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | | LOG(( "%f mc6843_finish_STZ: actual=%i\n", machine().time().as_double(), floppy_drive_get_current_track( img ) )); |
| 276 | LOG(( "%f mc6843_finish_STZ: actual=%i\n", machine().time().as_double(), img->floppy_drive_get_current_track() )); |
| 277 | 277 | |
| 278 | 278 | /* update state */ |
| 279 | 279 | m_CTAR = 0; |
| 280 | 280 | m_GCR = 0; |
| 281 | 281 | m_SAR = 0; |
| 282 | | m_STRB |= floppy_tk00_r(img) << 4; |
| 282 | m_STRB |= img->floppy_tk00_r() << 4; |
| 283 | 283 | |
| 284 | 284 | cmd_end( ); |
| 285 | 285 | } |
| r29179 | r29180 | |
| 289 | 289 | /* Seek bottom half */ |
| 290 | 290 | void mc6843_device::finish_SEK( ) |
| 291 | 291 | { |
| 292 | | device_t* img = floppy_image( ); |
| 292 | legacy_floppy_image_device* img = floppy_image( ); |
| 293 | 293 | |
| 294 | 294 | /* seek to track */ |
| 295 | 295 | // TODO: not sure how CTAR bit 7 is handled here, but this is the safest approach for now |
| 296 | | floppy_drive_seek( img, m_GCR - (m_CTAR & 0x7F) ); |
| 296 | img->floppy_drive_seek( m_GCR - (m_CTAR & 0x7F) ); |
| 297 | 297 | |
| 298 | | LOG(( "%f mc6843_finish_SEK: from %i to %i (actual=%i)\n", machine().time().as_double(), (m_CTAR & 0x7F), m_GCR, floppy_drive_get_current_track( img ) )); |
| 298 | LOG(( "%f mc6843_finish_SEK: from %i to %i (actual=%i)\n", machine().time().as_double(), (m_CTAR & 0x7F), m_GCR, img->floppy_drive_get_current_track() )); |
| 299 | 299 | |
| 300 | 300 | /* update state */ |
| 301 | 301 | m_CTAR = m_GCR; |
| r29179 | r29180 | |
| 308 | 308 | /* preamble to all sector read / write commands, returns 1 if found */ |
| 309 | 309 | int mc6843_device::address_search( chrn_id* id ) |
| 310 | 310 | { |
| 311 | | device_t* img = floppy_image( ); |
| 311 | legacy_floppy_image_device* img = floppy_image( ); |
| 312 | 312 | int r = 0; |
| 313 | 313 | |
| 314 | 314 | while ( 1 ) |
| 315 | 315 | { |
| 316 | | if ( ( ! floppy_drive_get_next_id( img, m_side, id ) ) || ( id->flags & ID_FLAG_CRC_ERROR_IN_ID_FIELD ) || ( id->N != 0 ) ) |
| 316 | if ( ( ! img->floppy_drive_get_next_id( m_side, id ) ) || ( id->flags & ID_FLAG_CRC_ERROR_IN_ID_FIELD ) || ( id->N != 0 ) ) |
| 317 | 317 | { |
| 318 | 318 | /* read address error */ |
| 319 | 319 | LOG(( "%f mc6843_address_search: get_next_id failed\n", machine().time().as_double() )); |
| r29179 | r29180 | |
| 343 | 343 | return 1; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | | if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) ) |
| 346 | if ( img->floppy_drive_get_flag_state( FLOPPY_DRIVE_INDEX ) ) |
| 347 | 347 | { |
| 348 | 348 | r++; |
| 349 | 349 | if ( r >= 4 ) |
| r29179 | r29180 | |
| 403 | 403 | void mc6843_device::cont_SR( ) |
| 404 | 404 | { |
| 405 | 405 | chrn_id id; |
| 406 | | device_t* img = floppy_image( ); |
| 406 | legacy_floppy_image_device* img = floppy_image( ); |
| 407 | 407 | |
| 408 | 408 | /* sector seek */ |
| 409 | 409 | if ( ! address_search_read( &id ) ) |
| 410 | 410 | return; |
| 411 | 411 | |
| 412 | 412 | /* sector read */ |
| 413 | | floppy_drive_read_sector_data( img, m_side, id.data_id, m_data, 128 ); |
| 413 | img->floppy_drive_read_sector_data( m_side, id.data_id, m_data, 128 ); |
| 414 | 414 | m_data_idx = 0; |
| 415 | 415 | m_data_size = 128; |
| 416 | 416 | m_STRA |= 0x01; /* set Data Transfer Request */ |
| r29179 | r29180 | |
| 551 | 551 | data = m_CTAR; |
| 552 | 552 | LOG(( "%f %s mc6843_r: read CTAR %i (actual=%i)\n", |
| 553 | 553 | machine().time().as_double(), machine().describe_context(), data, |
| 554 | | floppy_drive_get_current_track( floppy_image( ) ) )); |
| 554 | floppy_image()->floppy_drive_get_current_track())); |
| 555 | 555 | break; |
| 556 | 556 | |
| 557 | 557 | case 2: /* Interrupt Status Register (ISR) */ |
| r29179 | r29180 | |
| 569 | 569 | case 3: /* Status Register A (STRA) */ |
| 570 | 570 | { |
| 571 | 571 | /* update */ |
| 572 | | device_t* img = floppy_image( ); |
| 573 | | int flag = floppy_drive_get_flag_state( img, FLOPPY_DRIVE_READY); |
| 572 | legacy_floppy_image_device* img = floppy_image( ); |
| 573 | int flag = img->floppy_drive_get_flag_state( FLOPPY_DRIVE_READY); |
| 574 | 574 | m_STRA &= 0xa3; |
| 575 | 575 | if ( flag & FLOPPY_DRIVE_READY ) |
| 576 | 576 | m_STRA |= 0x04; |
| 577 | 577 | |
| 578 | | m_STRA |= !floppy_tk00_r(img) << 3; |
| 579 | | m_STRA |= !floppy_wpt_r(img) << 4; |
| 578 | m_STRA |= !img->floppy_tk00_r() << 3; |
| 579 | m_STRA |= !img->floppy_wpt_r() << 4; |
| 580 | 580 | |
| 581 | 581 | if ( m_index_pulse ) |
| 582 | 582 | m_STRA |= 0x40; |
| r29179 | r29180 | |
| 605 | 605 | data = m_LTAR; |
| 606 | 606 | LOG(( "%f %s mc6843_r: read LTAR %i (actual=%i)\n", |
| 607 | 607 | machine().time().as_double(), machine().describe_context(), data, |
| 608 | | floppy_drive_get_current_track( floppy_image( ) ) )); |
| 608 | floppy_image()->floppy_drive_get_current_track())); |
| 609 | 609 | break; |
| 610 | 610 | |
| 611 | 611 | default: |
| r29179 | r29180 | |
| 639 | 639 | if ( m_data_idx >= m_data_size ) |
| 640 | 640 | { |
| 641 | 641 | /* end of sector write */ |
| 642 | | device_t* img = floppy_image( ); |
| 642 | legacy_floppy_image_device* img = floppy_image( ); |
| 643 | 643 | |
| 644 | 644 | LOG(( "%f %s mc6843_w: write sector %i\n", machine().time().as_double(), machine().describe_context(), m_data_id )); |
| 645 | 645 | |
| 646 | | floppy_drive_write_sector_data( |
| 647 | | img, m_side, m_data_id, |
| 646 | img->floppy_drive_write_sector_data( |
| 647 | m_side, m_data_id, |
| 648 | 648 | m_data, m_data_size, |
| 649 | 649 | (cmd == CMD_SWD) ? ID_FLAG_DELETED_DATA : 0 ); |
| 650 | 650 | |
| r29179 | r29180 | |
| 701 | 701 | if ( (m_data[2] == 0) && (m_data[4] == 0) ) |
| 702 | 702 | { |
| 703 | 703 | /* valid address id field */ |
| 704 | | device_t* img = floppy_image( ); |
| 704 | legacy_floppy_image_device* img = floppy_image( ); |
| 705 | 705 | UINT8 track = m_data[1]; |
| 706 | 706 | UINT8 sector = m_data[3]; |
| 707 | 707 | UINT8 filler = 0xe5; /* standard Thomson filler */ |
| 708 | 708 | LOG(( "%f %s mc6843_w: address id detected track=%i sector=%i\n", machine().time().as_double(), machine().describe_context(), track, sector)); |
| 709 | | floppy_drive_format_sector( img, m_side, sector, track, 0, sector, 0, filler ); |
| 709 | img->floppy_drive_format_sector( m_side, sector, track, 0, sector, 0, filler ); |
| 710 | 710 | } |
| 711 | 711 | else |
| 712 | 712 | { |
| r29179 | r29180 | |
| 736 | 736 | m_CTAR = data; |
| 737 | 737 | LOG(( "%f %s mc6843_w: set CTAR to %i %02X (actual=%i) \n", |
| 738 | 738 | machine().time().as_double(), machine().describe_context(), m_CTAR, data, |
| 739 | | floppy_drive_get_current_track( floppy_image( ) ) )); |
| 739 | floppy_image()->floppy_drive_get_current_track())); |
| 740 | 740 | break; |
| 741 | 741 | |
| 742 | 742 | case 2: /* Command Register (CMR) */ |
| r29179 | r29180 | |
| 816 | 816 | m_LTAR = data & 0x7f; |
| 817 | 817 | LOG(( "%f %s mc6843_w: set LTAR to %i %02X (actual=%i)\n", |
| 818 | 818 | machine().time().as_double(), machine().describe_context(), m_LTAR, data, |
| 819 | | floppy_drive_get_current_track( floppy_image( ) ) )); |
| 819 | floppy_image()->floppy_drive_get_current_track())); |
| 820 | 820 | break; |
| 821 | 821 | |
| 822 | 822 | default: |
trunk/src/emu/machine/i8271.c
| r29179 | r29180 | |
| 14 | 14 | |
| 15 | 15 | #include "emu.h" |
| 16 | 16 | #include "i8271.h" |
| 17 | | #include "imagedev/flopdrv.h" |
| 18 | 17 | |
| 19 | 18 | /* data request */ |
| 20 | 19 | #define I8271_FLAGS_DATA_REQUEST 0x01 |
| r29179 | r29180 | |
| 238 | 237 | set_dma_drq(); |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | | device_t *i8271_device::current_image() |
| 240 | legacy_floppy_image_device *i8271_device::current_image() |
| 242 | 241 | { |
| 243 | 242 | if (m_floppy_drive_tags[m_drive]!=NULL) { |
| 244 | | return machine().device(m_floppy_drive_tags[m_drive]); |
| 243 | return machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[m_drive]); |
| 245 | 244 | } else { |
| 246 | 245 | return NULL; |
| 247 | 246 | } |
| r29179 | r29180 | |
| 250 | 249 | |
| 251 | 250 | void i8271_device::seek_to_track(int track) |
| 252 | 251 | { |
| 253 | | device_t *img = current_image(); |
| 252 | legacy_floppy_image_device *img = current_image(); |
| 254 | 253 | if (track==0) |
| 255 | 254 | { |
| 256 | 255 | /* seek to track 0 */ |
| r29179 | r29180 | |
| 259 | 258 | /*logerror("step\n"); */ |
| 260 | 259 | |
| 261 | 260 | /* track 0 not set, not seeked more than 255 tracks */ |
| 262 | | while (floppy_tk00_r(img) && (StepCount != 0)) |
| 261 | while (img->floppy_tk00_r() && (StepCount != 0)) |
| 263 | 262 | { |
| 264 | 263 | /* logerror("step\n"); */ |
| 265 | 264 | StepCount--; |
| 266 | | floppy_drive_seek(img, -1); |
| 265 | img->floppy_drive_seek(-1); |
| 267 | 266 | } |
| 268 | 267 | |
| 269 | 268 | m_CurrentTrack[m_drive] = 0; |
| r29179 | r29180 | |
| 297 | 296 | |
| 298 | 297 | |
| 299 | 298 | /* seek to track 0 */ |
| 300 | | floppy_drive_seek(img, SignedTracks); |
| 299 | img->floppy_drive_seek(SignedTracks); |
| 301 | 300 | |
| 302 | 301 | m_CurrentTrack[m_drive] = track; |
| 303 | 302 | } |
| r29179 | r29180 | |
| 610 | 609 | case I8271_COMMAND_WRITE_DATA_SINGLE_RECORD: |
| 611 | 610 | { |
| 612 | 611 | /* put the buffer to the sector */ |
| 613 | | floppy_drive_write_sector_data(current_image(), m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7),0); |
| 612 | current_image()->floppy_drive_write_sector_data(m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7),0); |
| 614 | 613 | |
| 615 | 614 | /* completed all sectors? */ |
| 616 | 615 | m_Counter--; |
| r29179 | r29180 | |
| 653 | 652 | if (find_sector()) |
| 654 | 653 | { |
| 655 | 654 | /* get the sector into the buffer */ |
| 656 | | floppy_drive_read_sector_data(current_image(), m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7)); |
| 655 | current_image()->floppy_drive_read_sector_data(m_side, m_data_id, m_pExecutionPhaseData, 1<<(m_ID_N+7)); |
| 657 | 656 | |
| 658 | 657 | /* initialise for reading */ |
| 659 | 658 | initialise_execution_phase_read(1<<(m_ID_N+7)); |
| r29179 | r29180 | |
| 672 | 671 | chrn_id id; |
| 673 | 672 | |
| 674 | 673 | /* get next id from disc */ |
| 675 | | floppy_drive_get_next_id(current_image(), m_side,&id); |
| 674 | current_image()->floppy_drive_get_next_id(m_side,&id); |
| 676 | 675 | |
| 677 | 676 | m_pExecutionPhaseData[0] = id.C; |
| 678 | 677 | m_pExecutionPhaseData[1] = id.H; |
| r29179 | r29180 | |
| 704 | 703 | |
| 705 | 704 | int i8271_device::find_sector() |
| 706 | 705 | { |
| 707 | | device_t *img = current_image(); |
| 706 | legacy_floppy_image_device *img = current_image(); |
| 708 | 707 | // int track_count_attempt; |
| 709 | 708 | |
| 710 | 709 | // track_count_attempt |
| r29179 | r29180 | |
| 719 | 718 | chrn_id id; |
| 720 | 719 | |
| 721 | 720 | /* get next id from disc */ |
| 722 | | if (floppy_drive_get_next_id(img, m_side,&id)) |
| 721 | if (img->floppy_drive_get_next_id(m_side,&id)) |
| 723 | 722 | { |
| 724 | 723 | /* tested on Amstrad CPC - All bytes must match, otherwise |
| 725 | 724 | a NO DATA error is reported */ |
| r29179 | r29180 | |
| 742 | 741 | } |
| 743 | 742 | |
| 744 | 743 | /* index set? */ |
| 745 | | if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX)) |
| 744 | if (img->floppy_drive_get_flag_state(FLOPPY_DRIVE_INDEX)) |
| 746 | 745 | { |
| 747 | 746 | index_count++; |
| 748 | 747 | } |
| r29179 | r29180 | |
| 759 | 758 | |
| 760 | 759 | void i8271_device::command_execute() |
| 761 | 760 | { |
| 762 | | device_t *img = current_image(); |
| 761 | legacy_floppy_image_device *img = current_image(); |
| 763 | 762 | |
| 764 | 763 | /* clear it = good completion status */ |
| 765 | 764 | /* this will be changed if anything bad happens! */ |
| r29179 | r29180 | |
| 885 | 884 | m_drive_control_input = (1<<6) | (1<<2); |
| 886 | 885 | |
| 887 | 886 | /* bit 3 = 0 if write protected */ |
| 888 | | m_drive_control_input |= floppy_wpt_r(img) << 3; |
| 887 | m_drive_control_input |= img->floppy_wpt_r() << 3; |
| 889 | 888 | |
| 890 | 889 | /* bit 1 = 0 if head at track 0 */ |
| 891 | | m_drive_control_input |= floppy_tk00_r(img) << 1; |
| 890 | m_drive_control_input |= img->floppy_tk00_r() << 1; |
| 892 | 891 | |
| 893 | 892 | /* need to setup this register based on drive selected */ |
| 894 | 893 | data = m_drive_control_input; |
| r29179 | r29180 | |
| 1021 | 1020 | |
| 1022 | 1021 | /* load head - on mini-sized drives this turns on the disc motor, |
| 1023 | 1022 | on standard-sized drives this loads the head and turns the motor on */ |
| 1024 | | floppy_mon_w(img, !BIT(m_CommandParameters[1], 3)); |
| 1025 | | floppy_drive_set_ready_state(img, 1, 1); |
| 1023 | img->floppy_mon_w(!BIT(m_CommandParameters[1], 3)); |
| 1024 | img->floppy_drive_set_ready_state(1, 1); |
| 1026 | 1025 | |
| 1027 | 1026 | /* step pin changed? if so perform a step in the direction indicated */ |
| 1028 | 1027 | if (((m_drive_control_output^m_CommandParameters[1]) & (1<<1))!=0) |
| r29179 | r29180 | |
| 1042 | 1041 | signed_tracks = -1; |
| 1043 | 1042 | } |
| 1044 | 1043 | |
| 1045 | | floppy_drive_seek(img, signed_tracks); |
| 1044 | img->floppy_drive_seek(signed_tracks); |
| 1046 | 1045 | } |
| 1047 | 1046 | } |
| 1048 | 1047 | |
| r29179 | r29180 | |
| 1081 | 1080 | /* these two do not appear to be set at all! ?? */ |
| 1082 | 1081 | |
| 1083 | 1082 | if (m_floppy_drive_tags[0]!=NULL) { |
| 1084 | | if (floppy_drive_get_flag_state(machine().device(m_floppy_drive_tags[0]), FLOPPY_DRIVE_READY)) |
| 1083 | if (machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[0])->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1085 | 1084 | { |
| 1086 | 1085 | status |= (1<<2); |
| 1087 | 1086 | } |
| 1088 | 1087 | } |
| 1089 | 1088 | |
| 1090 | 1089 | if (m_floppy_drive_tags[1]!=NULL) { |
| 1091 | | if (floppy_drive_get_flag_state(machine().device(m_floppy_drive_tags[1]), FLOPPY_DRIVE_READY)) |
| 1090 | if (machine().device<legacy_floppy_image_device>(m_floppy_drive_tags[1])->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1092 | 1091 | { |
| 1093 | 1092 | status |= (1<<6); |
| 1094 | 1093 | } |
| 1095 | 1094 | } |
| 1096 | 1095 | |
| 1097 | 1096 | /* bit 3 = 1 if write protected */ |
| 1098 | | status |= !floppy_wpt_r(img) << 3; |
| 1097 | status |= !img->floppy_wpt_r() << 3; |
| 1099 | 1098 | |
| 1100 | 1099 | /* bit 1 = 1 if head at track 0 */ |
| 1101 | | status |= !floppy_tk00_r(img) << 1; |
| 1100 | status |= !img->floppy_tk00_r() << 1; |
| 1102 | 1101 | |
| 1103 | 1102 | m_ResultRegister = status; |
| 1104 | 1103 | command_complete(1,0); |
| r29179 | r29180 | |
| 1140 | 1139 | |
| 1141 | 1140 | get_drive(); |
| 1142 | 1141 | |
| 1143 | | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1142 | if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1144 | 1143 | { |
| 1145 | 1144 | /* Completion type: operation intervention probably required for recovery */ |
| 1146 | 1145 | /* Completion code: Drive not ready */ |
| r29179 | r29180 | |
| 1173 | 1172 | |
| 1174 | 1173 | get_drive(); |
| 1175 | 1174 | |
| 1176 | | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1175 | if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1177 | 1176 | { |
| 1178 | 1177 | /* Completion type: operation intervention probably required for recovery */ |
| 1179 | 1178 | /* Completion code: Drive not ready */ |
| r29179 | r29180 | |
| 1212 | 1211 | |
| 1213 | 1212 | m_drive_control_output &=~1; |
| 1214 | 1213 | |
| 1215 | | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1214 | if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1216 | 1215 | { |
| 1217 | 1216 | /* Completion type: operation intervention probably required for recovery */ |
| 1218 | 1217 | /* Completion code: Drive not ready */ |
| r29179 | r29180 | |
| 1221 | 1220 | } |
| 1222 | 1221 | else |
| 1223 | 1222 | { |
| 1224 | | if (floppy_wpt_r(img) == CLEAR_LINE) |
| 1223 | if (img->floppy_wpt_r() == CLEAR_LINE) |
| 1225 | 1224 | { |
| 1226 | 1225 | /* Completion type: operation intervention probably required for recovery */ |
| 1227 | 1226 | /* Completion code: Drive write protected */ |
| r29179 | r29180 | |
| 1257 | 1256 | |
| 1258 | 1257 | m_drive_control_output &=~1; |
| 1259 | 1258 | |
| 1260 | | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1259 | if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1261 | 1260 | { |
| 1262 | 1261 | /* Completion type: operation intervention probably required for recovery */ |
| 1263 | 1262 | /* Completion code: Drive not ready */ |
| r29179 | r29180 | |
| 1266 | 1265 | } |
| 1267 | 1266 | else |
| 1268 | 1267 | { |
| 1269 | | if (floppy_wpt_r(img) == CLEAR_LINE) |
| 1268 | if (img->floppy_wpt_r() == CLEAR_LINE) |
| 1270 | 1269 | { |
| 1271 | 1270 | /* Completion type: operation intervention probably required for recovery */ |
| 1272 | 1271 | /* Completion code: Drive write protected */ |
| r29179 | r29180 | |
| 1296 | 1295 | |
| 1297 | 1296 | get_drive(); |
| 1298 | 1297 | |
| 1299 | | if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)) |
| 1298 | if (!img->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY)) |
| 1300 | 1299 | { |
| 1301 | 1300 | /* Completion type: operation intervention probably required for recovery */ |
| 1302 | 1301 | /* Completion code: Drive not ready */ |
trunk/src/emu/imagedev/flopdrv.c
| r29179 | r29180 | |
| 29 | 29 | TYPE DEFINITIONS |
| 30 | 30 | ***************************************************************************/ |
| 31 | 31 | |
| 32 | | struct floppy_drive |
| 33 | | { |
| 34 | | /* callbacks */ |
| 35 | | devcb_resolved_write_line out_idx_func; |
| 36 | | devcb_resolved_read_line in_mon_func; |
| 37 | | devcb_resolved_write_line out_tk00_func; |
| 38 | | devcb_resolved_write_line out_wpt_func; |
| 39 | | devcb_resolved_write_line out_rdy_func; |
| 40 | | devcb_resolved_write_line out_dskchg_func; |
| 41 | | |
| 42 | | /* state of input lines */ |
| 43 | | int drtn; /* direction */ |
| 44 | | int stp; /* step */ |
| 45 | | int wtg; /* write gate */ |
| 46 | | int mon; /* motor on */ |
| 47 | | |
| 48 | | /* state of output lines */ |
| 49 | | int idx; /* index pulse */ |
| 50 | | int tk00; /* track 00 */ |
| 51 | | int wpt; /* write protect */ |
| 52 | | int rdy; /* ready */ |
| 53 | | int dskchg; /* disk changed */ |
| 54 | | |
| 55 | | /* drive select logic */ |
| 56 | | int drive_id; |
| 57 | | int active; |
| 58 | | |
| 59 | | const floppy_interface *config; |
| 60 | | |
| 61 | | /* flags */ |
| 62 | | int flags; |
| 63 | | /* maximum track allowed */ |
| 64 | | int max_track; |
| 65 | | /* num sides */ |
| 66 | | int num_sides; |
| 67 | | /* current track - this may or may not relate to the present cylinder number |
| 68 | | stored by the fdc */ |
| 69 | | int current_track; |
| 70 | | |
| 71 | | /* index pulse timer */ |
| 72 | | emu_timer *index_timer; |
| 73 | | /* index pulse callback */ |
| 74 | | void (*index_pulse_callback)(device_t *controller,device_t *image, int state); |
| 75 | | /* rotation per minute => gives index pulse frequency */ |
| 76 | | float rpm; |
| 77 | | |
| 78 | | void (*ready_state_change_callback)(device_t *controller,device_t *img, int state); |
| 79 | | |
| 80 | | int id_index; |
| 81 | | |
| 82 | | device_t *controller; |
| 83 | | |
| 84 | | floppy_image_legacy *floppy; |
| 85 | | int track; |
| 86 | | void (*load_proc)(device_image_interface &image); |
| 87 | | void (*unload_proc)(device_image_interface &image); |
| 88 | | int floppy_drive_type; |
| 89 | | }; |
| 90 | | |
| 91 | | |
| 92 | 32 | struct floppy_error_map |
| 93 | 33 | { |
| 94 | 34 | floperr_t ferr; |
| r29179 | r29180 | |
| 115 | 55 | IMPLEMENTATION |
| 116 | 56 | ***************************************************************************/ |
| 117 | 57 | |
| 118 | | INLINE floppy_drive *get_safe_token(device_t *device) |
| 119 | | { |
| 120 | | assert( device != NULL ); |
| 121 | | return (floppy_drive *) downcast<legacy_floppy_image_device *>(device)->token(); |
| 122 | | } |
| 123 | 58 | |
| 124 | | floppy_image_legacy *flopimg_get_image(device_t *image) |
| 59 | floppy_image_legacy *legacy_floppy_image_device::flopimg_get_image() |
| 125 | 60 | { |
| 126 | | return get_safe_token(image)->floppy; |
| 61 | return m_floppy; |
| 127 | 62 | } |
| 128 | 63 | |
| 129 | | static int flopimg_get_sectors_per_track(device_t *image, int side) |
| 64 | int legacy_floppy_image_device::flopimg_get_sectors_per_track(int side) |
| 130 | 65 | { |
| 131 | 66 | floperr_t err; |
| 132 | 67 | int sector_count; |
| 133 | | floppy_drive *flopimg = get_safe_token( image ); |
| 134 | 68 | |
| 135 | | if (!flopimg || !flopimg->floppy) |
| 69 | if (!m_floppy) |
| 136 | 70 | return 0; |
| 137 | 71 | |
| 138 | | err = floppy_get_sector_count(flopimg->floppy, side, flopimg->track, §or_count); |
| 72 | err = floppy_get_sector_count(m_floppy, side, m_track, §or_count); |
| 139 | 73 | if (err) |
| 140 | 74 | return 0; |
| 141 | 75 | return sector_count; |
| 142 | 76 | } |
| 143 | 77 | |
| 144 | | static void flopimg_get_id_callback(device_t *image, chrn_id *id, int id_index, int side) |
| 78 | void legacy_floppy_image_device::flopimg_get_id_callback(chrn_id *id, int id_index, int side) |
| 145 | 79 | { |
| 146 | | floppy_drive *flopimg; |
| 147 | 80 | int cylinder, sector, N; |
| 148 | 81 | unsigned long flags; |
| 149 | 82 | UINT32 sector_length; |
| 150 | 83 | |
| 151 | | flopimg = get_safe_token( image ); |
| 152 | | if (!flopimg || !flopimg->floppy) |
| 84 | if (!m_floppy) |
| 153 | 85 | return; |
| 154 | 86 | |
| 155 | | floppy_get_indexed_sector_info(flopimg->floppy, side, flopimg->track, id_index, &cylinder, &side, §or, §or_length, &flags); |
| 87 | floppy_get_indexed_sector_info(m_floppy, side, m_track, id_index, &cylinder, &side, §or, §or_length, &flags); |
| 156 | 88 | |
| 157 | 89 | N = compute_log2(sector_length); |
| 158 | 90 | |
| r29179 | r29180 | |
| 164 | 96 | id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0; |
| 165 | 97 | } |
| 166 | 98 | |
| 167 | | static void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length) |
| 99 | void legacy_floppy_image_device::log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length) |
| 168 | 100 | { |
| 169 | 101 | char membuf[1024]; |
| 170 | 102 | int i; |
| r29179 | r29180 | |
| 173 | 105 | logerror("%s: head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf); |
| 174 | 106 | } |
| 175 | 107 | |
| 176 | | static void floppy_drive_set_geometry_absolute(device_t *img, int tracks, int sides) |
| 108 | void legacy_floppy_image_device::floppy_drive_set_geometry_absolute(int tracks, int sides) |
| 177 | 109 | { |
| 178 | | floppy_drive *pDrive = get_safe_token( img ); |
| 179 | | pDrive->max_track = tracks; |
| 180 | | pDrive->num_sides = sides; |
| 110 | m_max_track = tracks; |
| 111 | m_num_sides = sides; |
| 181 | 112 | } |
| 182 | 113 | |
| 183 | | void floppy_drive_set_geometry(device_t *img, floppy_type_t type) |
| 114 | void legacy_floppy_image_device::floppy_drive_set_geometry(floppy_type_t type) |
| 184 | 115 | { |
| 185 | | floppy_drive_set_geometry_absolute(img, type.max_track_number, type.head_number); |
| 116 | floppy_drive_set_geometry_absolute(type.max_track_number, type.head_number); |
| 186 | 117 | } |
| 187 | 118 | |
| 188 | | static TIMER_CALLBACK(floppy_drive_index_callback); |
| 189 | | |
| 190 | 119 | /* this is called on device init */ |
| 191 | | static void floppy_drive_init(device_t *img) |
| 120 | void legacy_floppy_image_device::floppy_drive_init() |
| 192 | 121 | { |
| 193 | | floppy_drive *pDrive = get_safe_token( img ); |
| 194 | | |
| 195 | 122 | /* initialise flags */ |
| 196 | | pDrive->flags = 0; |
| 197 | | pDrive->index_pulse_callback = NULL; |
| 198 | | pDrive->ready_state_change_callback = NULL; |
| 199 | | pDrive->index_timer = img->machine().scheduler().timer_alloc(FUNC(floppy_drive_index_callback), (void *) img); |
| 200 | | pDrive->idx = 0; |
| 123 | m_flags = 0; |
| 124 | m_index_pulse_callback = NULL; |
| 125 | m_ready_state_change_callback = NULL; |
| 126 | m_index_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(legacy_floppy_image_device::floppy_drive_index_callback),this)); |
| 127 | m_idx = 0; |
| 201 | 128 | |
| 202 | | floppy_drive_set_geometry(img, ((floppy_interface*)img->static_config())->floppy_type); |
| 129 | floppy_drive_set_geometry(((floppy_interface*)static_config())->floppy_type); |
| 203 | 130 | |
| 204 | 131 | /* initialise id index - not so important */ |
| 205 | | pDrive->id_index = 0; |
| 132 | m_id_index = 0; |
| 206 | 133 | /* initialise track */ |
| 207 | | pDrive->current_track = 0; |
| 134 | m_current_track = 0; |
| 208 | 135 | |
| 209 | 136 | /* default RPM */ |
| 210 | | pDrive->rpm = 300; |
| 137 | m_rpm = 300; |
| 211 | 138 | |
| 212 | | pDrive->controller = NULL; |
| 139 | m_controller = NULL; |
| 213 | 140 | |
| 214 | | pDrive->floppy_drive_type = FLOPPY_TYPE_REGULAR; |
| 141 | m_floppy_drive_type = FLOPPY_TYPE_REGULAR; |
| 215 | 142 | } |
| 216 | 143 | |
| 217 | 144 | /* index pulses at rpm/60 Hz, and stays high 1/20th of time */ |
| 218 | | static void floppy_drive_index_func(device_t *img) |
| 145 | void legacy_floppy_image_device::floppy_drive_index_func() |
| 219 | 146 | { |
| 220 | | floppy_drive *drive = get_safe_token( img ); |
| 147 | double ms = 1000.0 / (m_rpm / 60.0); |
| 221 | 148 | |
| 222 | | double ms = 1000.0 / (drive->rpm / 60.0); |
| 223 | | |
| 224 | | if (drive->idx) |
| 149 | if (m_idx) |
| 225 | 150 | { |
| 226 | | drive->idx = 0; |
| 227 | | drive->index_timer->adjust(attotime::from_double(ms*19/20/1000.0)); |
| 151 | m_idx = 0; |
| 152 | m_index_timer->adjust(attotime::from_double(ms*19/20/1000.0)); |
| 228 | 153 | } |
| 229 | 154 | else |
| 230 | 155 | { |
| 231 | | drive->idx = 1; |
| 232 | | drive->index_timer->adjust(attotime::from_double(ms/20/1000.0)); |
| 156 | m_idx = 1; |
| 157 | m_index_timer->adjust(attotime::from_double(ms/20/1000.0)); |
| 233 | 158 | } |
| 234 | 159 | |
| 235 | | drive->out_idx_func(drive->idx); |
| 160 | m_out_idx_func(m_idx); |
| 236 | 161 | |
| 237 | | if (drive->index_pulse_callback) |
| 238 | | drive->index_pulse_callback(drive->controller, img, drive->idx); |
| 162 | if (m_index_pulse_callback) |
| 163 | m_index_pulse_callback(m_controller, this, m_idx); |
| 239 | 164 | } |
| 240 | 165 | |
| 241 | | static TIMER_CALLBACK(floppy_drive_index_callback) |
| 166 | TIMER_CALLBACK_MEMBER(legacy_floppy_image_device::floppy_drive_index_callback) |
| 242 | 167 | { |
| 243 | | device_t *image = (device_t *) ptr; |
| 244 | | floppy_drive_index_func(image); |
| 168 | floppy_drive_index_func(); |
| 245 | 169 | } |
| 246 | 170 | |
| 247 | 171 | /*************************************************************************/ |
| 248 | 172 | /* IO_FLOPPY device functions */ |
| 249 | 173 | |
| 250 | 174 | /* set flag state */ |
| 251 | | void floppy_drive_set_flag_state(device_t *img, int flag, int state) |
| 175 | void legacy_floppy_image_device::floppy_drive_set_flag_state(int flag, int state) |
| 252 | 176 | { |
| 253 | | floppy_drive *drv = get_safe_token( img ); |
| 254 | 177 | int prev_state; |
| 255 | 178 | int new_state; |
| 256 | 179 | |
| 257 | 180 | /* get old state */ |
| 258 | | prev_state = drv->flags & flag; |
| 181 | prev_state = m_flags & flag; |
| 259 | 182 | |
| 260 | 183 | /* set new state */ |
| 261 | | drv->flags &= ~flag; |
| 184 | m_flags &= ~flag; |
| 262 | 185 | if (state) |
| 263 | | drv->flags |= flag; |
| 186 | m_flags |= flag; |
| 264 | 187 | |
| 265 | 188 | /* get new state */ |
| 266 | | new_state = drv->flags & flag; |
| 189 | new_state = m_flags & flag; |
| 267 | 190 | |
| 268 | 191 | /* changed state? */ |
| 269 | 192 | if (prev_state ^ new_state) |
| r29179 | r29180 | |
| 271 | 194 | if (flag & FLOPPY_DRIVE_READY) |
| 272 | 195 | { |
| 273 | 196 | /* trigger state change callback */ |
| 274 | | drv->out_rdy_func(new_state ? ASSERT_LINE : CLEAR_LINE); |
| 197 | m_out_rdy_func(new_state ? ASSERT_LINE : CLEAR_LINE); |
| 275 | 198 | |
| 276 | | if (drv->ready_state_change_callback) |
| 277 | | drv->ready_state_change_callback(drv->controller, img, new_state); |
| 199 | if (m_ready_state_change_callback) |
| 200 | m_ready_state_change_callback(m_controller, this, new_state); |
| 278 | 201 | } |
| 279 | 202 | } |
| 280 | 203 | } |
| r29179 | r29180 | |
| 282 | 205 | /* for pc, drive is always ready, for amstrad,pcw,spectrum it is only ready under |
| 283 | 206 | a fixed set of circumstances */ |
| 284 | 207 | /* use this to set ready state of drive */ |
| 285 | | void floppy_drive_set_ready_state(device_t *img, int state, int flag) |
| 286 | | { |
| 287 | | floppy_drive *drive = get_safe_token(img); |
| 288 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 208 | void legacy_floppy_image_device::floppy_drive_set_ready_state(int state, int flag) |
| 209 | { |
| 289 | 210 | if (flag) |
| 290 | 211 | { |
| 291 | 212 | /* set ready only if drive is present, disk is in the drive, |
| r29179 | r29180 | |
| 293 | 214 | |
| 294 | 215 | /* drive present? */ |
| 295 | 216 | /* disk inserted? */ |
| 296 | | if (image->exists()) |
| 217 | if (exists()) |
| 297 | 218 | { |
| 298 | | if (drive->mon == CLEAR_LINE) |
| 219 | if (m_mon == CLEAR_LINE) |
| 299 | 220 | { |
| 300 | 221 | /* set state */ |
| 301 | | floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state); |
| 222 | floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, state); |
| 302 | 223 | return; |
| 303 | 224 | } |
| 304 | 225 | } |
| 305 | | floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, 0); |
| 226 | floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, 0); |
| 306 | 227 | } |
| 307 | 228 | else |
| 308 | 229 | { |
| 309 | 230 | /* force ready state - for PC driver */ |
| 310 | | floppy_drive_set_flag_state(img, FLOPPY_DRIVE_READY, state); |
| 231 | floppy_drive_set_flag_state(FLOPPY_DRIVE_READY, state); |
| 311 | 232 | } |
| 312 | 233 | } |
| 313 | 234 | |
| 314 | 235 | /* get flag state */ |
| 315 | | int floppy_drive_get_flag_state(device_t *img, int flag) |
| 236 | int legacy_floppy_image_device::floppy_drive_get_flag_state(int flag) |
| 316 | 237 | { |
| 317 | | floppy_drive *drv = get_safe_token( img ); |
| 318 | 238 | int drive_flags; |
| 319 | 239 | int flags; |
| 320 | 240 | |
| 321 | 241 | flags = 0; |
| 322 | 242 | |
| 323 | | drive_flags = drv->flags; |
| 243 | drive_flags = m_flags; |
| 324 | 244 | |
| 325 | 245 | /* these flags are independent of a real drive/disk image */ |
| 326 | 246 | flags |= drive_flags & (FLOPPY_DRIVE_READY | FLOPPY_DRIVE_INDEX); |
| r29179 | r29180 | |
| 331 | 251 | } |
| 332 | 252 | |
| 333 | 253 | |
| 334 | | void floppy_drive_seek(device_t *img, signed int signed_tracks) |
| 335 | | { |
| 336 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 337 | | floppy_drive *pDrive; |
| 254 | void legacy_floppy_image_device::floppy_drive_seek(signed int signed_tracks) |
| 255 | { |
| 256 | LOG(("seek from: %d delta: %d\n",m_current_track, signed_tracks)); |
| 338 | 257 | |
| 339 | | pDrive = get_safe_token( img ); |
| 340 | | |
| 341 | | LOG(("seek from: %d delta: %d\n",pDrive->current_track, signed_tracks)); |
| 342 | | |
| 343 | 258 | /* update position */ |
| 344 | | pDrive->current_track+=signed_tracks; |
| 259 | m_current_track+=signed_tracks; |
| 345 | 260 | |
| 346 | | if (pDrive->current_track<0) |
| 261 | if (m_current_track<0) |
| 347 | 262 | { |
| 348 | | pDrive->current_track = 0; |
| 263 | m_current_track = 0; |
| 349 | 264 | } |
| 350 | 265 | else |
| 351 | | if (pDrive->current_track>=pDrive->max_track) |
| 266 | if (m_current_track>=m_max_track) |
| 352 | 267 | { |
| 353 | | pDrive->current_track = pDrive->max_track-1; |
| 268 | m_current_track = m_max_track-1; |
| 354 | 269 | } |
| 355 | 270 | |
| 356 | 271 | /* set track 0 flag */ |
| 357 | | pDrive->tk00 = (pDrive->current_track == 0) ? CLEAR_LINE : ASSERT_LINE; |
| 358 | | pDrive->out_tk00_func(pDrive->tk00); |
| 272 | m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE; |
| 273 | m_out_tk00_func(m_tk00); |
| 359 | 274 | |
| 360 | 275 | /* clear disk changed flag */ |
| 361 | | pDrive->dskchg = ASSERT_LINE; |
| 362 | | //flopimg->out_dskchg_func(flopimg->dskchg); |
| 276 | m_dskchg = ASSERT_LINE; |
| 277 | //m_out_dskchg_func(m_dskchg); |
| 363 | 278 | |
| 364 | 279 | /* inform disk image of step operation so it can cache information */ |
| 365 | | if (image->exists()) |
| 366 | | pDrive->track = pDrive->current_track; |
| 280 | if (exists()) |
| 281 | m_track = m_current_track; |
| 367 | 282 | |
| 368 | | pDrive->id_index = 0; |
| 283 | m_id_index = 0; |
| 369 | 284 | } |
| 370 | 285 | |
| 371 | 286 | |
| 372 | 287 | /* this is not accurate. But it will do for now */ |
| 373 | | int floppy_drive_get_next_id(device_t *img, int side, chrn_id *id) |
| 288 | int legacy_floppy_image_device::floppy_drive_get_next_id(int side, chrn_id *id) |
| 374 | 289 | { |
| 375 | | floppy_drive *pDrive; |
| 376 | 290 | int spt; |
| 377 | 291 | |
| 378 | | pDrive = get_safe_token( img ); |
| 379 | | |
| 380 | 292 | /* get sectors per track */ |
| 381 | | spt = flopimg_get_sectors_per_track(img, side); |
| 293 | spt = flopimg_get_sectors_per_track(side); |
| 382 | 294 | |
| 383 | 295 | /* set index */ |
| 384 | | if ((pDrive->id_index==(spt-1)) || (spt==0)) |
| 296 | if ((m_id_index==(spt-1)) || (spt==0)) |
| 385 | 297 | { |
| 386 | | floppy_drive_set_flag_state(img, FLOPPY_DRIVE_INDEX, 1); |
| 298 | floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 1); |
| 387 | 299 | } |
| 388 | 300 | else |
| 389 | 301 | { |
| 390 | | floppy_drive_set_flag_state(img, FLOPPY_DRIVE_INDEX, 0); |
| 302 | floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 0); |
| 391 | 303 | } |
| 392 | 304 | |
| 393 | 305 | /* get id */ |
| 394 | 306 | if (spt!=0) |
| 395 | 307 | { |
| 396 | | flopimg_get_id_callback(img, id, pDrive->id_index, side); |
| 308 | flopimg_get_id_callback(id, m_id_index, side); |
| 397 | 309 | } |
| 398 | 310 | |
| 399 | | pDrive->id_index++; |
| 311 | m_id_index++; |
| 400 | 312 | if (spt!=0) |
| 401 | | pDrive->id_index %= spt; |
| 313 | m_id_index %= spt; |
| 402 | 314 | else |
| 403 | | pDrive->id_index = 0; |
| 315 | m_id_index = 0; |
| 404 | 316 | |
| 405 | 317 | return (spt == 0) ? 0 : 1; |
| 406 | 318 | } |
| 407 | 319 | |
| 408 | | void floppy_drive_read_track_data_info_buffer(device_t *img, int side, void *ptr, int *length ) |
| 320 | void legacy_floppy_image_device::floppy_drive_read_track_data_info_buffer(int side, void *ptr, int *length ) |
| 409 | 321 | { |
| 410 | | floppy_drive *flopimg; |
| 411 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 412 | | |
| 413 | | if (image->exists()) |
| 322 | if (exists()) |
| 414 | 323 | { |
| 415 | | flopimg = get_safe_token( img ); |
| 416 | | if (!flopimg || !flopimg->floppy) |
| 324 | if (!m_floppy) |
| 417 | 325 | return; |
| 418 | 326 | |
| 419 | | floppy_read_track_data(flopimg->floppy, side, flopimg->track, ptr, *length); |
| 327 | floppy_read_track_data(m_floppy, side, m_track, ptr, *length); |
| 420 | 328 | } |
| 421 | 329 | } |
| 422 | 330 | |
| 423 | | void floppy_drive_write_track_data_info_buffer(device_t *img, int side, const void *ptr, int *length ) |
| 331 | void legacy_floppy_image_device::floppy_drive_write_track_data_info_buffer(int side, const void *ptr, int *length ) |
| 424 | 332 | { |
| 425 | | floppy_drive *flopimg; |
| 426 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 427 | | |
| 428 | | if (image->exists()) |
| 333 | if (exists()) |
| 429 | 334 | { |
| 430 | | flopimg = get_safe_token( img ); |
| 431 | | if (!flopimg || !flopimg->floppy) |
| 335 | if (!m_floppy) |
| 432 | 336 | return; |
| 433 | 337 | |
| 434 | | floppy_write_track_data(flopimg->floppy, side, flopimg->track, ptr, *length); |
| 338 | floppy_write_track_data(m_floppy, side, m_track, ptr, *length); |
| 435 | 339 | } |
| 436 | 340 | } |
| 437 | 341 | |
| 438 | | void floppy_drive_format_sector(device_t *img, int side, int sector_index,int c,int h, int r, int n, int filler) |
| 342 | void legacy_floppy_image_device::floppy_drive_format_sector(int side, int sector_index,int c,int h, int r, int n, int filler) |
| 439 | 343 | { |
| 440 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 441 | | |
| 442 | | if (image->exists()) |
| 344 | if (exists()) |
| 443 | 345 | { |
| 444 | | /* if (drv->interface_.format_sector) |
| 445 | | drv->interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/ |
| 346 | /* if (m_interface_.format_sector) |
| 347 | m_interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/ |
| 446 | 348 | } |
| 447 | 349 | } |
| 448 | 350 | |
| 449 | | void floppy_drive_read_sector_data(device_t *img, int side, int index1, void *ptr, int length) |
| 351 | void legacy_floppy_image_device::floppy_drive_read_sector_data(int side, int index1, void *ptr, int length) |
| 450 | 352 | { |
| 451 | | floppy_drive *flopimg; |
| 452 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 453 | | |
| 454 | | if (image->exists()) |
| 353 | if (exists()) |
| 455 | 354 | { |
| 456 | | flopimg = get_safe_token( img ); |
| 457 | | if (!flopimg || !flopimg->floppy) |
| 355 | if (!m_floppy) |
| 458 | 356 | return; |
| 459 | 357 | |
| 460 | | floppy_read_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length); |
| 358 | floppy_read_indexed_sector(m_floppy, side, m_track, index1, 0, ptr, length); |
| 461 | 359 | |
| 462 | 360 | if (LOG_FLOPPY) |
| 463 | | log_readwrite("sector_read", side, flopimg->track, index1, (const char *)ptr, length); |
| 361 | log_readwrite("sector_read", side, m_track, index1, (const char *)ptr, length); |
| 464 | 362 | |
| 465 | 363 | } |
| 466 | 364 | } |
| 467 | 365 | |
| 468 | | void floppy_drive_write_sector_data(device_t *img, int side, int index1, const void *ptr,int length, int ddam) |
| 366 | void legacy_floppy_image_device::floppy_drive_write_sector_data(int side, int index1, const void *ptr,int length, int ddam) |
| 469 | 367 | { |
| 470 | | floppy_drive *flopimg; |
| 471 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 472 | | |
| 473 | | if (image->exists()) |
| 368 | if (exists()) |
| 474 | 369 | { |
| 475 | | flopimg = get_safe_token( img ); |
| 476 | | if (!flopimg || !flopimg->floppy) |
| 370 | if (!m_floppy) |
| 477 | 371 | return; |
| 478 | 372 | |
| 479 | 373 | if (LOG_FLOPPY) |
| 480 | | log_readwrite("sector_write", side, flopimg->track, index1, (const char *)ptr, length); |
| 374 | log_readwrite("sector_write", side, m_track, index1, (const char *)ptr, length); |
| 481 | 375 | |
| 482 | | floppy_write_indexed_sector(flopimg->floppy, side, flopimg->track, index1, 0, ptr, length, ddam); |
| 376 | floppy_write_indexed_sector(m_floppy, side, m_track, index1, 0, ptr, length, ddam); |
| 483 | 377 | } |
| 484 | 378 | } |
| 485 | 379 | |
| 486 | | void floppy_install_load_proc(device_t *image, void (*proc)(device_image_interface &image)) |
| 380 | void legacy_floppy_image_device::floppy_install_load_proc(void (*proc)(device_image_interface &image)) |
| 487 | 381 | { |
| 488 | | floppy_drive *flopimg = get_safe_token( image ); |
| 489 | | flopimg->load_proc = proc; |
| 382 | m_load_proc = proc; |
| 490 | 383 | } |
| 491 | 384 | |
| 492 | | void floppy_install_unload_proc(device_t *image, void (*proc)(device_image_interface &image)) |
| 385 | void legacy_floppy_image_device::floppy_install_unload_proc(void (*proc)(device_image_interface &image)) |
| 493 | 386 | { |
| 494 | | floppy_drive *flopimg = get_safe_token( image ); |
| 495 | | flopimg->unload_proc = proc; |
| 387 | m_unload_proc = proc; |
| 496 | 388 | } |
| 497 | 389 | |
| 498 | 390 | /* set the callback for the index pulse */ |
| 499 | | void floppy_drive_set_index_pulse_callback(device_t *img, void (*callback)(device_t *controller,device_t *image, int state)) |
| 391 | void legacy_floppy_image_device::floppy_drive_set_index_pulse_callback(void (*callback)(device_t *controller, device_t *img, int state)) |
| 500 | 392 | { |
| 501 | | floppy_drive *pDrive = get_safe_token( img ); |
| 502 | | pDrive->index_pulse_callback = callback; |
| 393 | m_index_pulse_callback = callback; |
| 503 | 394 | } |
| 504 | 395 | |
| 505 | | |
| 506 | | void floppy_drive_set_ready_state_change_callback(device_t *img, void (*callback)(device_t *controller,device_t *img, int state)) |
| 396 | void legacy_floppy_image_device::floppy_drive_set_ready_state_change_callback(void (*callback)(device_t *controller,device_t *img, int state)) |
| 507 | 397 | { |
| 508 | | floppy_drive *pDrive = get_safe_token( img ); |
| 509 | | pDrive->ready_state_change_callback = callback; |
| 398 | m_ready_state_change_callback = callback; |
| 510 | 399 | } |
| 511 | 400 | |
| 512 | | int floppy_drive_get_current_track(device_t *img) |
| 401 | int legacy_floppy_image_device::floppy_drive_get_current_track() |
| 513 | 402 | { |
| 514 | | floppy_drive *drv = get_safe_token( img ); |
| 515 | | return drv->current_track; |
| 403 | return m_current_track; |
| 516 | 404 | } |
| 517 | 405 | |
| 518 | | UINT64 floppy_drive_get_current_track_size(device_t *img, int head) |
| 406 | UINT64 legacy_floppy_image_device::floppy_drive_get_current_track_size(int head) |
| 519 | 407 | { |
| 520 | | floppy_drive *drv = get_safe_token( img ); |
| 521 | 408 | int size = 0; |
| 522 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 523 | | |
| 524 | | if (image->exists()) |
| 409 | if (exists()) |
| 525 | 410 | { |
| 526 | | size = floppy_get_track_size(drv->floppy, head, drv->current_track); |
| 411 | size = floppy_get_track_size(m_floppy, head, m_current_track); |
| 527 | 412 | } |
| 528 | 413 | |
| 529 | 414 | return size; |
| 530 | 415 | } |
| 531 | 416 | |
| 532 | | void floppy_drive_set_rpm(device_t *img, float rpm) |
| 417 | void legacy_floppy_image_device::floppy_drive_set_rpm(float rpm) |
| 533 | 418 | { |
| 534 | | floppy_drive *drv = get_safe_token( img ); |
| 535 | | drv->rpm = rpm; |
| 419 | m_rpm = rpm; |
| 536 | 420 | } |
| 537 | 421 | |
| 538 | | void floppy_drive_set_controller(device_t *img, device_t *controller) |
| 422 | void legacy_floppy_image_device::floppy_drive_set_controller(device_t *controller) |
| 539 | 423 | { |
| 540 | | floppy_drive *drv = get_safe_token( img ); |
| 541 | | drv->controller = controller; |
| 424 | m_controller = controller; |
| 542 | 425 | } |
| 543 | 426 | |
| 544 | | static int internal_floppy_device_load(device_image_interface *image, int create_format, option_resolution *create_args) |
| 427 | int legacy_floppy_image_device::internal_floppy_device_load(int create_format, option_resolution *create_args) |
| 545 | 428 | { |
| 546 | 429 | floperr_t err; |
| 547 | | floppy_drive *flopimg; |
| 548 | 430 | const struct FloppyFormat *floppy_options; |
| 549 | 431 | int floppy_flags, i; |
| 550 | 432 | const char *extension; |
| 551 | 433 | |
| 552 | | /* look up instance data */ |
| 553 | | flopimg = get_safe_token( &image->device() ); |
| 434 | device_image_interface *image = NULL; |
| 435 | interface(image); /* figure out the floppy options */ |
| 436 | floppy_options = ((floppy_interface*)static_config())->formats; |
| 554 | 437 | |
| 555 | | /* figure out the floppy options */ |
| 556 | | floppy_options = ((floppy_interface*)image->device().static_config())->formats; |
| 557 | | |
| 558 | | if (image->has_been_created()) |
| 438 | if (has_been_created()) |
| 559 | 439 | { |
| 560 | 440 | /* creating an image */ |
| 561 | 441 | assert(create_format >= 0); |
| 562 | | err = floppy_create((void *) image, &image_ioprocs, &floppy_options[create_format], create_args, &flopimg->floppy); |
| 442 | err = floppy_create((void *) image, &image_ioprocs, &floppy_options[create_format], create_args, &m_floppy); |
| 563 | 443 | if (err) |
| 564 | 444 | goto error; |
| 565 | 445 | } |
| 566 | 446 | else |
| 567 | 447 | { |
| 568 | 448 | /* opening an image */ |
| 569 | | floppy_flags = !image->is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; |
| 570 | | extension = image->filetype(); |
| 571 | | err = floppy_open_choices((void *) image, &image_ioprocs, extension, floppy_options, floppy_flags, &flopimg->floppy); |
| 449 | floppy_flags = !is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; |
| 450 | extension = filetype(); |
| 451 | err = floppy_open_choices((void *) image, &image_ioprocs, extension, floppy_options, floppy_flags, &m_floppy); |
| 572 | 452 | if (err) |
| 573 | 453 | goto error; |
| 574 | 454 | } |
| 575 | | if (floppy_callbacks(flopimg->floppy)->get_heads_per_disk && floppy_callbacks(flopimg->floppy)->get_tracks_per_disk) |
| 455 | if (floppy_callbacks(m_floppy)->get_heads_per_disk && floppy_callbacks(m_floppy)->get_tracks_per_disk) |
| 576 | 456 | { |
| 577 | | floppy_drive_set_geometry_absolute(&image->device(), |
| 578 | | floppy_get_tracks_per_disk(flopimg->floppy), |
| 579 | | floppy_get_heads_per_disk(flopimg->floppy)); |
| 457 | floppy_drive_set_geometry_absolute(floppy_get_tracks_per_disk(m_floppy),floppy_get_heads_per_disk(m_floppy)); |
| 580 | 458 | } |
| 581 | 459 | /* disk changed */ |
| 582 | | flopimg->dskchg = CLEAR_LINE; |
| 460 | m_dskchg = CLEAR_LINE; |
| 583 | 461 | |
| 584 | 462 | return IMAGE_INIT_PASS; |
| 585 | 463 | |
| r29179 | r29180 | |
| 587 | 465 | for (i = 0; i < ARRAY_LENGTH(errmap); i++) |
| 588 | 466 | { |
| 589 | 467 | if (err == errmap[i].ferr) |
| 590 | | image->seterror(errmap[i].ierr, errmap[i].message); |
| 468 | seterror(errmap[i].ierr, errmap[i].message); |
| 591 | 469 | } |
| 592 | 470 | return IMAGE_INIT_FAIL; |
| 593 | 471 | } |
| 594 | 472 | |
| 595 | | static TIMER_CALLBACK( set_wpt ) |
| 473 | TIMER_CALLBACK_MEMBER( legacy_floppy_image_device::set_wpt ) |
| 596 | 474 | { |
| 597 | | floppy_drive *flopimg = (floppy_drive *)ptr; |
| 598 | | |
| 599 | | flopimg->wpt = param; |
| 600 | | flopimg->out_wpt_func(param); |
| 475 | m_wpt = param; |
| 476 | m_out_wpt_func(param); |
| 601 | 477 | } |
| 602 | 478 | |
| 603 | | device_t *floppy_get_device(running_machine &machine,int drive) |
| 479 | legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive) |
| 604 | 480 | { |
| 605 | 481 | switch(drive) { |
| 606 | | case 0 : return machine.device(FLOPPY_0); |
| 607 | | case 1 : return machine.device(FLOPPY_1); |
| 608 | | case 2 : return machine.device(FLOPPY_2); |
| 609 | | case 3 : return machine.device(FLOPPY_3); |
| 482 | case 0 : return machine.device<legacy_floppy_image_device>(FLOPPY_0); |
| 483 | case 1 : return machine.device<legacy_floppy_image_device>(FLOPPY_1); |
| 484 | case 2 : return machine.device<legacy_floppy_image_device>(FLOPPY_2); |
| 485 | case 3 : return machine.device<legacy_floppy_image_device>(FLOPPY_3); |
| 610 | 486 | } |
| 611 | 487 | return NULL; |
| 612 | 488 | } |
| 613 | 489 | |
| 614 | | int floppy_get_drive_type(device_t *image) |
| 490 | int legacy_floppy_image_device::floppy_get_drive_type() |
| 615 | 491 | { |
| 616 | | floppy_drive *flopimg = get_safe_token( image ); |
| 617 | | return flopimg->floppy_drive_type; |
| 492 | return m_floppy_drive_type; |
| 618 | 493 | } |
| 619 | 494 | |
| 620 | | void floppy_set_type(device_t *image,int ftype) |
| 495 | void legacy_floppy_image_device::floppy_set_type(int ftype) |
| 621 | 496 | { |
| 622 | | floppy_drive *flopimg = get_safe_token( image ); |
| 623 | | flopimg->floppy_drive_type = ftype; |
| 497 | m_floppy_drive_type = ftype; |
| 624 | 498 | } |
| 625 | 499 | |
| 626 | | device_t *floppy_get_device_by_type(running_machine &machine,int ftype,int drive) |
| 500 | legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive) |
| 627 | 501 | { |
| 628 | 502 | int i; |
| 629 | 503 | int cnt = 0; |
| 630 | 504 | for (i=0;i<4;i++) { |
| 631 | | device_t *disk = floppy_get_device(machine,i); |
| 632 | | if (floppy_get_drive_type(disk)==ftype) { |
| 505 | legacy_floppy_image_device *disk = floppy_get_device(machine,i); |
| 506 | if (disk->floppy_get_drive_type()==ftype) { |
| 633 | 507 | if (cnt==drive) { |
| 634 | 508 | return disk; |
| 635 | 509 | } |
| r29179 | r29180 | |
| 649 | 523 | return drive; |
| 650 | 524 | } |
| 651 | 525 | |
| 652 | | int floppy_get_drive_by_type(device_t *image,int ftype) |
| 526 | int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype) |
| 653 | 527 | { |
| 654 | 528 | int i,drive =0; |
| 655 | 529 | for (i=0;i<4;i++) { |
| 656 | | device_t *disk = floppy_get_device(image->machine(),i); |
| 657 | | if (floppy_get_drive_type(disk)==ftype) { |
| 530 | legacy_floppy_image_device *disk = floppy_get_device(image->machine(),i); |
| 531 | if (disk->floppy_get_drive_type()==ftype) { |
| 658 | 532 | if (image==disk) { |
| 659 | 533 | return drive; |
| 660 | 534 | } |
| r29179 | r29180 | |
| 667 | 541 | int floppy_get_count(running_machine &machine) |
| 668 | 542 | { |
| 669 | 543 | int cnt = 0; |
| 670 | | if (machine.device(FLOPPY_0)) cnt++; |
| 671 | | if (machine.device(FLOPPY_1)) cnt++; |
| 672 | | if (machine.device(FLOPPY_2)) cnt++; |
| 673 | | if (machine.device(FLOPPY_3)) cnt++; |
| 544 | if (machine.device<legacy_floppy_image_device>(FLOPPY_0)) cnt++; |
| 545 | if (machine.device<legacy_floppy_image_device>(FLOPPY_1)) cnt++; |
| 546 | if (machine.device<legacy_floppy_image_device>(FLOPPY_2)) cnt++; |
| 547 | if (machine.device<legacy_floppy_image_device>(FLOPPY_3)) cnt++; |
| 674 | 548 | return cnt; |
| 675 | 549 | } |
| 676 | 550 | |
| 677 | 551 | |
| 678 | 552 | /* drive select 0 */ |
| 679 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds0_w ) |
| 553 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds0_w ) |
| 680 | 554 | { |
| 681 | | floppy_drive *drive = get_safe_token(device); |
| 682 | | |
| 683 | 555 | if (state == CLEAR_LINE) |
| 684 | | drive->active = (drive->drive_id == 0); |
| 556 | m_active = (m_drive_id == 0); |
| 685 | 557 | } |
| 686 | 558 | |
| 687 | 559 | /* drive select 1 */ |
| 688 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds1_w ) |
| 560 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds1_w ) |
| 689 | 561 | { |
| 690 | | floppy_drive *drive = get_safe_token(device); |
| 691 | | |
| 692 | 562 | if (state == CLEAR_LINE) |
| 693 | | drive->active = (drive->drive_id == 1); |
| 563 | m_active = (m_drive_id == 1); |
| 694 | 564 | } |
| 695 | 565 | |
| 696 | 566 | /* drive select 2 */ |
| 697 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds2_w ) |
| 567 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds2_w ) |
| 698 | 568 | { |
| 699 | | floppy_drive *drive = get_safe_token(device); |
| 700 | | |
| 701 | 569 | if (state == CLEAR_LINE) |
| 702 | | drive->active = (drive->drive_id == 2); |
| 570 | m_active = (m_drive_id == 2); |
| 703 | 571 | } |
| 704 | 572 | |
| 705 | 573 | /* drive select 3 */ |
| 706 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds3_w ) |
| 574 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds3_w ) |
| 707 | 575 | { |
| 708 | | floppy_drive *drive = get_safe_token(device); |
| 709 | | |
| 710 | 576 | if (state == CLEAR_LINE) |
| 711 | | drive->active = (drive->drive_id == 3); |
| 577 | m_active = (m_drive_id == 3); |
| 712 | 578 | } |
| 713 | 579 | |
| 714 | 580 | /* shortcut to write all four ds lines */ |
| 715 | | WRITE8_DEVICE_HANDLER( floppy_ds_w ) |
| 581 | WRITE8_MEMBER( legacy_floppy_image_device::floppy_ds_w ) |
| 716 | 582 | { |
| 717 | | floppy_ds0_w(device, BIT(data, 0)); |
| 718 | | floppy_ds1_w(device, BIT(data, 1)); |
| 719 | | floppy_ds2_w(device, BIT(data, 2)); |
| 720 | | floppy_ds3_w(device, BIT(data, 3)); |
| 583 | floppy_ds0_w(BIT(data, 0)); |
| 584 | floppy_ds1_w(BIT(data, 1)); |
| 585 | floppy_ds2_w(BIT(data, 2)); |
| 586 | floppy_ds3_w(BIT(data, 3)); |
| 721 | 587 | } |
| 722 | 588 | |
| 723 | 589 | /* motor on, active low */ |
| 724 | | WRITE_LINE_DEVICE_HANDLER( floppy_mon_w ) |
| 590 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_mon_w ) |
| 725 | 591 | { |
| 726 | | floppy_drive *drive = get_safe_token(device); |
| 727 | | device_image_interface *image = dynamic_cast<device_image_interface *>(device); |
| 728 | 592 | /* force off if there is no attached image */ |
| 729 | | if (!image->exists()) |
| 593 | if (!exists()) |
| 730 | 594 | state = ASSERT_LINE; |
| 731 | 595 | |
| 732 | 596 | /* off -> on */ |
| 733 | | if (drive->mon && state == CLEAR_LINE) |
| 597 | if (m_mon && state == CLEAR_LINE) |
| 734 | 598 | { |
| 735 | | drive->idx = 0; |
| 736 | | floppy_drive_index_func(device); |
| 599 | m_idx = 0; |
| 600 | floppy_drive_index_func(); |
| 737 | 601 | } |
| 738 | 602 | |
| 739 | 603 | /* on -> off */ |
| 740 | | else if (drive->mon == CLEAR_LINE && state) |
| 741 | | drive->index_timer->adjust(attotime::zero); |
| 604 | else if (m_mon == CLEAR_LINE && state) |
| 605 | m_index_timer->adjust(attotime::zero); |
| 742 | 606 | |
| 743 | | drive->mon = state; |
| 607 | m_mon = state; |
| 744 | 608 | } |
| 745 | 609 | |
| 746 | 610 | /* direction */ |
| 747 | | WRITE_LINE_DEVICE_HANDLER( floppy_drtn_w ) |
| 611 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_drtn_w ) |
| 748 | 612 | { |
| 749 | | floppy_drive *drive = get_safe_token(device); |
| 750 | | drive->drtn = state; |
| 613 | m_drtn = state; |
| 751 | 614 | } |
| 752 | 615 | |
| 753 | 616 | /* write data */ |
| 754 | | WRITE_LINE_DEVICE_HANDLER( floppy_wtd_w ) |
| 617 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtd_w ) |
| 755 | 618 | { |
| 756 | 619 | } |
| 757 | 620 | |
| 758 | 621 | /* step */ |
| 759 | | WRITE_LINE_DEVICE_HANDLER( floppy_stp_w ) |
| 622 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w ) |
| 760 | 623 | { |
| 761 | | floppy_drive *drive = get_safe_token(device); |
| 762 | 624 | |
| 763 | 625 | /* move head one track when going from high to low and write gate is high */ |
| 764 | | if (drive->active && drive->stp && state == CLEAR_LINE && drive->wtg) |
| 626 | if (m_active && m_stp && state == CLEAR_LINE && m_wtg) |
| 765 | 627 | { |
| 766 | 628 | /* move head according to the direction line */ |
| 767 | | if (drive->drtn) |
| 629 | if (m_drtn) |
| 768 | 630 | { |
| 769 | 631 | /* move head outward */ |
| 770 | | if (drive->current_track > 0) |
| 771 | | drive->current_track--; |
| 632 | if (m_current_track > 0) |
| 633 | m_current_track--; |
| 772 | 634 | |
| 773 | 635 | /* are we at track 0 now? */ |
| 774 | | drive->tk00 = (drive->current_track == 0) ? CLEAR_LINE : ASSERT_LINE; |
| 636 | m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE; |
| 775 | 637 | } |
| 776 | 638 | else |
| 777 | 639 | { |
| 778 | 640 | /* move head inward */ |
| 779 | | if (drive->current_track < drive->max_track) |
| 780 | | drive->current_track++; |
| 641 | if (m_current_track < m_max_track) |
| 642 | m_current_track++; |
| 781 | 643 | |
| 782 | 644 | /* we can't be at track 0 here, so reset the line */ |
| 783 | | drive->tk00 = ASSERT_LINE; |
| 645 | m_tk00 = ASSERT_LINE; |
| 784 | 646 | } |
| 785 | 647 | |
| 786 | 648 | /* update track 0 line with new status */ |
| 787 | | drive->out_tk00_func(drive->tk00); |
| 649 | m_out_tk00_func(m_tk00); |
| 788 | 650 | } |
| 789 | 651 | |
| 790 | | drive->stp = state; |
| 652 | m_stp = state; |
| 791 | 653 | } |
| 792 | 654 | |
| 793 | 655 | /* write gate */ |
| 794 | | WRITE_LINE_DEVICE_HANDLER( floppy_wtg_w ) |
| 656 | WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtg_w ) |
| 795 | 657 | { |
| 796 | | floppy_drive *drive = get_safe_token(device); |
| 797 | | drive->wtg = state; |
| 658 | m_wtg = state; |
| 798 | 659 | } |
| 799 | 660 | |
| 800 | 661 | /* write protect signal, active low */ |
| 801 | | READ_LINE_DEVICE_HANDLER( floppy_wpt_r ) |
| 662 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_wpt_r ) |
| 802 | 663 | { |
| 803 | | floppy_drive *drive = get_safe_token(device); |
| 804 | | return drive->wpt; |
| 664 | return m_wpt; |
| 805 | 665 | } |
| 806 | 666 | |
| 807 | 667 | /* track 0 detect */ |
| 808 | | READ_LINE_DEVICE_HANDLER( floppy_tk00_r ) |
| 668 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_tk00_r ) |
| 809 | 669 | { |
| 810 | | floppy_drive *drive = get_safe_token(device); |
| 811 | | return drive->tk00; |
| 670 | return m_tk00; |
| 812 | 671 | } |
| 813 | 672 | |
| 814 | 673 | /* disk changed */ |
| 815 | | READ_LINE_DEVICE_HANDLER( floppy_dskchg_r ) |
| 674 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_dskchg_r ) |
| 816 | 675 | { |
| 817 | | floppy_drive *drive = get_safe_token(device); |
| 818 | | return drive->dskchg; |
| 676 | return m_dskchg; |
| 819 | 677 | } |
| 820 | 678 | |
| 821 | 679 | /* 2-sided disk */ |
| 822 | | READ_LINE_DEVICE_HANDLER( floppy_twosid_r ) |
| 680 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_twosid_r ) |
| 823 | 681 | { |
| 824 | | floppy_drive *drive = get_safe_token(device); |
| 825 | | |
| 826 | | if (drive->floppy == NULL) |
| 682 | if (m_floppy == NULL) |
| 827 | 683 | return ASSERT_LINE; |
| 828 | 684 | else |
| 829 | | return !floppy_get_heads_per_disk(drive->floppy); |
| 685 | return !floppy_get_heads_per_disk(m_floppy); |
| 830 | 686 | } |
| 831 | 687 | |
| 832 | | READ_LINE_DEVICE_HANDLER( floppy_index_r ) |
| 688 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_index_r ) |
| 833 | 689 | { |
| 834 | | floppy_drive *drive = get_safe_token(device); |
| 835 | | return drive->idx; |
| 690 | return m_idx; |
| 836 | 691 | } |
| 837 | 692 | |
| 838 | | READ_LINE_DEVICE_HANDLER( floppy_ready_r ) |
| 693 | READ_LINE_MEMBER( legacy_floppy_image_device::floppy_ready_r ) |
| 839 | 694 | { |
| 840 | | return !(floppy_drive_get_flag_state(device, FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY); |
| 695 | return !(floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY); |
| 841 | 696 | } |
| 842 | 697 | |
| 843 | 698 | // device type definition |
| r29179 | r29180 | |
| 849 | 704 | |
| 850 | 705 | legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 851 | 706 | : device_t(mconfig, LEGACY_FLOPPY, "Floppy Disk", tag, owner, clock, "legacy_floppy_image", __FILE__), |
| 852 | | device_image_interface(mconfig, *this), |
| 853 | | m_token(NULL) |
| 707 | device_image_interface(mconfig, *this) |
| 854 | 708 | { |
| 855 | | m_token = global_alloc_clear(floppy_drive); |
| 856 | 709 | } |
| 857 | 710 | |
| 858 | 711 | legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 859 | 712 | : device_t(mconfig, type, name, tag, owner, clock, shortname, source), |
| 860 | | device_image_interface(mconfig, *this), |
| 861 | | m_token(NULL) |
| 713 | device_image_interface(mconfig, *this) |
| 862 | 714 | { |
| 863 | | m_token = global_alloc_clear(floppy_drive); |
| 864 | 715 | } |
| 865 | 716 | |
| 866 | 717 | //------------------------------------------------- |
| r29179 | r29180 | |
| 869 | 720 | |
| 870 | 721 | legacy_floppy_image_device::~legacy_floppy_image_device() |
| 871 | 722 | { |
| 872 | | global_free(m_token); |
| 873 | 723 | } |
| 874 | 724 | |
| 875 | 725 | //------------------------------------------------- |
| r29179 | r29180 | |
| 878 | 728 | |
| 879 | 729 | void legacy_floppy_image_device::device_start() |
| 880 | 730 | { |
| 881 | | floppy_drive *floppy = get_safe_token( this ); |
| 882 | | floppy->config = (const floppy_interface*)static_config(); |
| 883 | | floppy_drive_init(this); |
| 731 | m_config = (const floppy_interface*)static_config(); |
| 732 | floppy_drive_init(); |
| 884 | 733 | |
| 885 | | floppy->drive_id = floppy_get_drive(this); |
| 886 | | floppy->active = FALSE; |
| 734 | m_drive_id = floppy_get_drive(this); |
| 735 | m_active = FALSE; |
| 887 | 736 | |
| 888 | 737 | /* resolve callbacks */ |
| 889 | | floppy->out_idx_func.resolve(floppy->config->out_idx_func, *this); |
| 890 | | floppy->in_mon_func.resolve(floppy->config->in_mon_func, *this); |
| 891 | | floppy->out_tk00_func.resolve(floppy->config->out_tk00_func, *this); |
| 892 | | floppy->out_wpt_func.resolve(floppy->config->out_wpt_func, *this); |
| 893 | | floppy->out_rdy_func.resolve(floppy->config->out_rdy_func, *this); |
| 894 | | // floppy->out_dskchg_func.resolve(floppy->config->out_dskchg_func, *this); |
| 738 | m_out_idx_func.resolve(m_config->out_idx_func, *this); |
| 739 | m_in_mon_func.resolve(m_config->in_mon_func, *this); |
| 740 | m_out_tk00_func.resolve(m_config->out_tk00_func, *this); |
| 741 | m_out_wpt_func.resolve(m_config->out_wpt_func, *this); |
| 742 | m_out_rdy_func.resolve(m_config->out_rdy_func, *this); |
| 743 | // m_out_dskchg_func.resolve(m_config->out_dskchg_func, *this); |
| 895 | 744 | |
| 896 | 745 | /* by default we are not write-protected */ |
| 897 | | floppy->wpt = ASSERT_LINE; |
| 898 | | floppy->out_wpt_func(floppy->wpt); |
| 746 | m_wpt = ASSERT_LINE; |
| 747 | m_out_wpt_func(m_wpt); |
| 899 | 748 | |
| 900 | 749 | /* not at track 0 */ |
| 901 | | floppy->tk00 = ASSERT_LINE; |
| 902 | | floppy->out_tk00_func(floppy->tk00); |
| 750 | m_tk00 = ASSERT_LINE; |
| 751 | m_out_tk00_func(m_tk00); |
| 903 | 752 | |
| 904 | 753 | /* motor off */ |
| 905 | | floppy->mon = ASSERT_LINE; |
| 754 | m_mon = ASSERT_LINE; |
| 906 | 755 | |
| 907 | 756 | /* disk changed */ |
| 908 | | floppy->dskchg = CLEAR_LINE; |
| 909 | | // floppy->out_dskchg_func(floppy->dskchg); |
| 757 | m_dskchg = CLEAR_LINE; |
| 758 | // m_out_dskchg_func(m_dskchg); |
| 910 | 759 | } |
| 911 | 760 | |
| 912 | 761 | |
| r29179 | r29180 | |
| 936 | 785 | |
| 937 | 786 | bool legacy_floppy_image_device::call_create(int format_type, option_resolution *format_options) |
| 938 | 787 | { |
| 939 | | return internal_floppy_device_load(this, format_type, format_options); |
| 788 | return internal_floppy_device_load(format_type, format_options); |
| 940 | 789 | } |
| 941 | 790 | |
| 942 | 791 | bool legacy_floppy_image_device::call_load() |
| 943 | 792 | { |
| 944 | | floppy_drive *flopimg; |
| 945 | | int retVal = internal_floppy_device_load(this, -1, NULL); |
| 946 | | flopimg = get_safe_token( this); |
| 793 | int retVal = internal_floppy_device_load(-1, NULL); |
| 947 | 794 | if (retVal==IMAGE_INIT_PASS) { |
| 948 | 795 | /* if we have one of our hacky unload procs, call it */ |
| 949 | | if (flopimg->load_proc) |
| 950 | | flopimg->load_proc(*this); |
| 796 | if (m_load_proc) |
| 797 | m_load_proc(*this); |
| 951 | 798 | } |
| 952 | 799 | |
| 953 | 800 | /* push disk halfway into drive */ |
| 954 | | flopimg->wpt = CLEAR_LINE; |
| 955 | | flopimg->out_wpt_func(flopimg->wpt); |
| 801 | m_wpt = CLEAR_LINE; |
| 802 | m_out_wpt_func(m_wpt); |
| 956 | 803 | |
| 957 | 804 | /* set timer for disk load */ |
| 958 | 805 | int next_wpt; |
| r29179 | r29180 | |
| 962 | 809 | else |
| 963 | 810 | next_wpt = CLEAR_LINE; |
| 964 | 811 | |
| 965 | | machine().scheduler().timer_set(attotime::from_msec(250), FUNC(set_wpt), next_wpt, flopimg); |
| 812 | machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), next_wpt); |
| 966 | 813 | |
| 967 | 814 | return retVal; |
| 968 | 815 | } |
| 969 | 816 | |
| 970 | 817 | void legacy_floppy_image_device::call_unload() |
| 971 | 818 | { |
| 972 | | floppy_drive *flopimg = get_safe_token( this); |
| 973 | | if (flopimg->unload_proc) |
| 974 | | flopimg->unload_proc(*this); |
| 819 | if (m_unload_proc) |
| 820 | m_unload_proc(*this); |
| 975 | 821 | |
| 976 | | floppy_close(flopimg->floppy); |
| 977 | | flopimg->floppy = NULL; |
| 822 | floppy_close(m_floppy); |
| 823 | m_floppy = NULL; |
| 978 | 824 | |
| 979 | 825 | /* disk changed */ |
| 980 | | flopimg->dskchg = CLEAR_LINE; |
| 981 | | //flopimg->out_dskchg_func(flopimg->dskchg); |
| 826 | m_dskchg = CLEAR_LINE; |
| 827 | //m_out_dskchg_func(m_dskchg); |
| 982 | 828 | |
| 983 | 829 | /* pull disk halfway out of drive */ |
| 984 | | flopimg->wpt = CLEAR_LINE; |
| 985 | | flopimg->out_wpt_func(flopimg->wpt); |
| 830 | m_wpt = CLEAR_LINE; |
| 831 | m_out_wpt_func(m_wpt); |
| 986 | 832 | |
| 987 | 833 | /* set timer for disk eject */ |
| 988 | | machine().scheduler().timer_set(attotime::from_msec(250), FUNC(set_wpt), ASSERT_LINE, flopimg); |
| 834 | machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), ASSERT_LINE); |
| 989 | 835 | } |
| 990 | 836 | |
| 991 | 837 | void legacy_floppy_image_device::call_display_info() |
trunk/src/emu/imagedev/flopdrv.h
| r29179 | r29180 | |
| 90 | 90 | /* set if index has just occurred */ |
| 91 | 91 | #define FLOPPY_DRIVE_INDEX 0x0020 |
| 92 | 92 | |
| 93 | | /* a callback which will be executed if the ready state of the drive changes e.g. not ready->ready, ready->not ready */ |
| 94 | | void floppy_drive_set_ready_state_change_callback(device_t *img, void (*callback)(device_t *controller,device_t *img, int state)); |
| 95 | 93 | |
| 96 | | void floppy_drive_set_index_pulse_callback(device_t *img, void (*callback)(device_t *controller,device_t *image, int state)); |
| 97 | | |
| 98 | | /* set flag state */ |
| 99 | | int floppy_drive_get_flag_state(device_t *img, int flag); |
| 100 | | /* get flag state */ |
| 101 | | void floppy_drive_set_flag_state(device_t *img, int flag, int state); |
| 102 | | /* get current physical track drive is on */ |
| 103 | | int floppy_drive_get_current_track(device_t *img); |
| 104 | | /* get current physical track size */ |
| 105 | | UINT64 floppy_drive_get_current_track_size(device_t *img, int head); |
| 106 | | |
| 107 | | /* get next id from track, 1 if got a id, 0 if no id was got */ |
| 108 | | int floppy_drive_get_next_id(device_t *img, int side, chrn_id *); |
| 109 | | /* set ready state of drive. If flag == 1, set ready state only if drive present, |
| 110 | | disk is in drive, and motor is on. Otherwise set ready state to the state passed */ |
| 111 | | void floppy_drive_set_ready_state(device_t *img, int state, int flag); |
| 112 | | |
| 113 | | /* seek up or down */ |
| 114 | | void floppy_drive_seek(device_t *img, signed int signed_tracks); |
| 115 | | |
| 116 | | void floppy_drive_read_track_data_info_buffer(device_t *img, int side, void *ptr, int *length ); |
| 117 | | void floppy_drive_write_track_data_info_buffer(device_t *img, int side, const void *ptr, int *length ); |
| 118 | | void floppy_drive_format_sector(device_t *img, int side, int sector_index, int c, int h, int r, int n, int filler); |
| 119 | | void floppy_drive_read_sector_data(device_t *img, int side, int index1, void *pBuffer, int length); |
| 120 | | void floppy_drive_write_sector_data(device_t *img, int side, int index1, const void *pBuffer, int length, int ddam); |
| 121 | | |
| 122 | | /* set motor speed to get correct index pulses |
| 123 | | standard RPM are 300 RPM (common) and 360 RPM |
| 124 | | Note: this actually only works for soft sectored disks: one index pulse per |
| 125 | | track. |
| 126 | | */ |
| 127 | | void floppy_drive_set_rpm(device_t *image, float rpm); |
| 128 | | |
| 129 | | void floppy_drive_set_controller(device_t *img, device_t *controller); |
| 130 | | |
| 131 | | floppy_image_legacy *flopimg_get_image(device_t *image); |
| 132 | | |
| 133 | | /* hack for apple II; replace this when we think of something better */ |
| 134 | | void floppy_install_unload_proc(device_t *image, void (*proc)(device_image_interface &image)); |
| 135 | | |
| 136 | | void floppy_install_load_proc(device_t *image, void (*proc)(device_image_interface &image)); |
| 137 | | |
| 138 | | device_t *floppy_get_device(running_machine &machine,int drive); |
| 139 | | device_t *floppy_get_device_by_type(running_machine &machine,int ftype,int drive); |
| 140 | | int floppy_get_drive_type(device_t *image); |
| 141 | | void floppy_set_type(device_t *image,int ftype); |
| 142 | | int floppy_get_count(running_machine &machine); |
| 143 | | |
| 144 | | int floppy_get_drive(device_t *image); |
| 145 | | int floppy_get_drive_by_type(device_t *image,int ftype); |
| 146 | | |
| 147 | | void floppy_drive_set_geometry(device_t *img, floppy_type_t type); |
| 148 | | |
| 149 | | /* drive select lines */ |
| 150 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds0_w ); |
| 151 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds1_w ); |
| 152 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds2_w ); |
| 153 | | WRITE_LINE_DEVICE_HANDLER( floppy_ds3_w ); |
| 154 | | DECLARE_WRITE8_DEVICE_HANDLER( floppy_ds_w ); |
| 155 | | |
| 156 | | WRITE_LINE_DEVICE_HANDLER( floppy_mon_w ); |
| 157 | | WRITE_LINE_DEVICE_HANDLER( floppy_drtn_w ); |
| 158 | | WRITE_LINE_DEVICE_HANDLER( floppy_stp_w ); |
| 159 | | WRITE_LINE_DEVICE_HANDLER( floppy_wtd_w ); |
| 160 | | WRITE_LINE_DEVICE_HANDLER( floppy_wtg_w ); |
| 161 | | |
| 162 | | /* write-protect */ |
| 163 | | READ_LINE_DEVICE_HANDLER( floppy_wpt_r ); |
| 164 | | |
| 165 | | /* track 0 detect */ |
| 166 | | READ_LINE_DEVICE_HANDLER( floppy_tk00_r ); |
| 167 | | |
| 168 | | /* disk changed */ |
| 169 | | READ_LINE_DEVICE_HANDLER( floppy_dskchg_r ); |
| 170 | | |
| 171 | | /* 2-sided disk */ |
| 172 | | READ_LINE_DEVICE_HANDLER( floppy_twosid_r ); |
| 173 | | |
| 174 | | // index pulse |
| 175 | | READ_LINE_DEVICE_HANDLER( floppy_index_r ); |
| 176 | | |
| 177 | | // drive ready |
| 178 | | READ_LINE_DEVICE_HANDLER( floppy_ready_r ); |
| 179 | | |
| 180 | 94 | class legacy_floppy_image_device : public device_t, |
| 181 | 95 | public device_image_interface |
| 182 | 96 | { |
| r29179 | r29180 | |
| 203 | 117 | virtual const char *file_extensions() const { return m_extension_list; } |
| 204 | 118 | virtual const option_guide *create_option_guide() const { return floppy_option_guide; } |
| 205 | 119 | |
| 206 | | // access to legacy token |
| 207 | | struct floppy_drive *token() const { assert(m_token != NULL); return m_token; } |
| 120 | floppy_image_legacy *flopimg_get_image(); |
| 121 | void floppy_drive_set_geometry(floppy_type_t type); |
| 122 | void floppy_drive_set_flag_state(int flag, int state); |
| 123 | void floppy_drive_set_ready_state(int state, int flag); |
| 124 | int floppy_drive_get_flag_state(int flag); |
| 125 | void floppy_drive_seek(signed int signed_tracks); |
| 126 | int floppy_drive_get_next_id(int side, chrn_id *id); |
| 127 | void floppy_drive_read_track_data_info_buffer(int side, void *ptr, int *length ); |
| 128 | void floppy_drive_write_track_data_info_buffer(int side, const void *ptr, int *length ); |
| 129 | void floppy_drive_format_sector(int side, int sector_index,int c,int h, int r, int n, int filler); |
| 130 | void floppy_drive_read_sector_data(int side, int index1, void *ptr, int length); |
| 131 | void floppy_drive_write_sector_data(int side, int index1, const void *ptr,int length, int ddam); |
| 132 | void floppy_install_load_proc(void (*proc)(device_image_interface &image)); |
| 133 | void floppy_install_unload_proc(void (*proc)(device_image_interface &image)); |
| 134 | void floppy_drive_set_index_pulse_callback(void (*callback)(device_t *controller,device_t *image, int state)); |
| 135 | void floppy_drive_set_ready_state_change_callback(void (*callback)(device_t *controller,device_t *img, int state)); |
| 136 | int floppy_drive_get_current_track(); |
| 137 | UINT64 floppy_drive_get_current_track_size(int head); |
| 138 | void floppy_drive_set_rpm(float rpm); |
| 139 | void floppy_drive_set_controller(device_t *controller); |
| 140 | int floppy_get_drive_type(); |
| 141 | void floppy_set_type(int ftype); |
| 142 | WRITE_LINE_MEMBER( floppy_ds0_w ); |
| 143 | WRITE_LINE_MEMBER( floppy_ds1_w ); |
| 144 | WRITE_LINE_MEMBER( floppy_ds2_w ); |
| 145 | WRITE_LINE_MEMBER( floppy_ds3_w ); |
| 146 | WRITE8_MEMBER( floppy_ds_w ); |
| 147 | WRITE_LINE_MEMBER( floppy_mon_w ); |
| 148 | WRITE_LINE_MEMBER( floppy_drtn_w ); |
| 149 | WRITE_LINE_MEMBER( floppy_wtd_w ); |
| 150 | WRITE_LINE_MEMBER( floppy_stp_w ); |
| 151 | WRITE_LINE_MEMBER( floppy_wtg_w ); |
| 152 | READ_LINE_MEMBER( floppy_wpt_r ); |
| 153 | READ_LINE_MEMBER( floppy_tk00_r ); |
| 154 | READ_LINE_MEMBER( floppy_dskchg_r ); |
| 155 | READ_LINE_MEMBER( floppy_twosid_r ); |
| 156 | READ_LINE_MEMBER( floppy_index_r ); |
| 157 | READ_LINE_MEMBER( floppy_ready_r ); |
| 158 | |
| 159 | |
| 160 | private: |
| 161 | int flopimg_get_sectors_per_track(int side); |
| 162 | void flopimg_get_id_callback(chrn_id *id, int id_index, int side); |
| 163 | void log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length); |
| 164 | void floppy_drive_set_geometry_absolute(int tracks, int sides); |
| 165 | TIMER_CALLBACK_MEMBER(floppy_drive_index_callback); |
| 166 | void floppy_drive_init(); |
| 167 | void floppy_drive_index_func(); |
| 168 | TIMER_CALLBACK(floppy_drive_index_callback); |
| 169 | int internal_floppy_device_load(int create_format, option_resolution *create_args); |
| 170 | TIMER_CALLBACK_MEMBER( set_wpt ); |
| 171 | |
| 208 | 172 | protected: |
| 209 | 173 | // device overrides |
| 210 | 174 | virtual void device_config_complete(); |
| 211 | 175 | virtual void device_start(); |
| 212 | 176 | |
| 213 | | struct floppy_drive *m_token; |
| 177 | /* callbacks */ |
| 178 | devcb_resolved_write_line m_out_idx_func; |
| 179 | devcb_resolved_read_line m_in_mon_func; |
| 180 | devcb_resolved_write_line m_out_tk00_func; |
| 181 | devcb_resolved_write_line m_out_wpt_func; |
| 182 | devcb_resolved_write_line m_out_rdy_func; |
| 183 | devcb_resolved_write_line m_out_dskchg_func; |
| 184 | |
| 185 | /* state of input lines */ |
| 186 | int m_drtn; /* direction */ |
| 187 | int m_stp; /* step */ |
| 188 | int m_wtg; /* write gate */ |
| 189 | int m_mon; /* motor on */ |
| 190 | |
| 191 | /* state of output lines */ |
| 192 | int m_idx; /* index pulse */ |
| 193 | int m_tk00; /* track 00 */ |
| 194 | int m_wpt; /* write protect */ |
| 195 | int m_rdy; /* ready */ |
| 196 | int m_dskchg; /* disk changed */ |
| 197 | |
| 198 | /* drive select logic */ |
| 199 | int m_drive_id; |
| 200 | int m_active; |
| 201 | |
| 202 | const floppy_interface *m_config; |
| 203 | |
| 204 | /* flags */ |
| 205 | int m_flags; |
| 206 | /* maximum track allowed */ |
| 207 | int m_max_track; |
| 208 | /* num sides */ |
| 209 | int m_num_sides; |
| 210 | /* current track - this may or may not relate to the present cylinder number |
| 211 | stored by the fdc */ |
| 212 | int m_current_track; |
| 213 | |
| 214 | /* index pulse timer */ |
| 215 | emu_timer *m_index_timer; |
| 216 | /* index pulse callback */ |
| 217 | void (*m_index_pulse_callback)(device_t *controller,device_t *image, int state); |
| 218 | /* rotation per minute => gives index pulse frequency */ |
| 219 | float m_rpm; |
| 220 | |
| 221 | void (*m_ready_state_change_callback)(device_t *controller,device_t *img, int state); |
| 222 | |
| 223 | int m_id_index; |
| 224 | |
| 225 | device_t *m_controller; |
| 226 | |
| 227 | floppy_image_legacy *m_floppy; |
| 228 | int m_track; |
| 229 | void (*m_load_proc)(device_image_interface &image); |
| 230 | void (*m_unload_proc)(device_image_interface &image); |
| 231 | int m_floppy_drive_type; |
| 232 | |
| 214 | 233 | char m_extension_list[256]; |
| 215 | 234 | }; |
| 216 | 235 | |
| 217 | 236 | // device type definition |
| 218 | 237 | extern const device_type LEGACY_FLOPPY; |
| 219 | 238 | |
| 239 | |
| 240 | |
| 241 | legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive); |
| 242 | legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive); |
| 243 | int floppy_get_drive(device_t *image); |
| 244 | int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype); |
| 245 | int floppy_get_count(running_machine &machine); |
| 246 | |
| 247 | |
| 220 | 248 | /*************************************************************************** |
| 221 | 249 | DEVICE CONFIGURATION MACROS |
| 222 | 250 | ***************************************************************************/ |