diff options
Diffstat (limited to 'src/devices/imagedev/flopdrv.cpp')
-rw-r--r-- | src/devices/imagedev/flopdrv.cpp | 441 |
1 files changed, 101 insertions, 340 deletions
diff --git a/src/devices/imagedev/flopdrv.cpp b/src/devices/imagedev/flopdrv.cpp index bf42b1070ea..9f1e2ff0c96 100644 --- a/src/devices/imagedev/flopdrv.cpp +++ b/src/devices/imagedev/flopdrv.cpp @@ -14,17 +14,23 @@ */ #include "emu.h" -#include "formats/imageutl.h" #include "flopdrv.h" -#define VERBOSE 0 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) +#include "softlist_dev.h" + +#include "formats/imageutl.h" + +#include "util/ioprocs.h" +#include "util/ioprocsfilter.h" + +//#define VERBOSE 1 +#include "logmacro.h" + /*************************************************************************** CONSTANTS ***************************************************************************/ -#define FLOPDRVTAG "flopdrv" #define LOG_FLOPPY 0 /*************************************************************************** @@ -34,8 +40,7 @@ struct floppy_error_map { floperr_t ferr; - image_error_t ierr; - const char *message; + std::error_condition ierr; }; @@ -46,64 +51,23 @@ struct floppy_error_map static const floppy_error_map errmap[] = { - { FLOPPY_ERROR_SUCCESS, IMAGE_ERROR_SUCCESS }, - { FLOPPY_ERROR_INTERNAL, IMAGE_ERROR_INTERNAL }, - { FLOPPY_ERROR_UNSUPPORTED, IMAGE_ERROR_UNSUPPORTED }, - { FLOPPY_ERROR_OUTOFMEMORY, IMAGE_ERROR_OUTOFMEMORY }, - { FLOPPY_ERROR_INVALIDIMAGE, IMAGE_ERROR_INVALIDIMAGE } + { FLOPPY_ERROR_SUCCESS, { } }, + { FLOPPY_ERROR_INTERNAL, { image_error::INTERNAL } }, + { FLOPPY_ERROR_UNSUPPORTED, { image_error::UNSUPPORTED } }, + { FLOPPY_ERROR_OUTOFMEMORY, { std::errc::not_enough_memory } }, + { FLOPPY_ERROR_INVALIDIMAGE, { image_error::INVALIDIMAGE } } }; /*************************************************************************** IMPLEMENTATION ***************************************************************************/ - -floppy_image_legacy *legacy_floppy_image_device::flopimg_get_image() -{ - return m_floppy; -} - -int legacy_floppy_image_device::flopimg_get_sectors_per_track(int side) -{ - floperr_t err; - int sector_count; - - if (!m_floppy) - return 0; - - err = floppy_get_sector_count(m_floppy, side, m_track, §or_count); - if (err) - return 0; - return sector_count; -} - -void legacy_floppy_image_device::flopimg_get_id_callback(chrn_id *id, int id_index, int side) -{ - int cylinder, sector, N; - unsigned long flags; - uint32_t sector_length; - - if (!m_floppy) - return; - - floppy_get_indexed_sector_info(m_floppy, side, m_track, id_index, &cylinder, &side, §or, §or_length, &flags); - - N = compute_log2(sector_length); - - id->C = cylinder; - id->H = side; - id->R = sector; - id->data_id = id_index; - id->flags = flags; - id->N = ((N >= 7) && (N <= 10)) ? N - 7 : 0; -} - void legacy_floppy_image_device::log_readwrite(const char *name, int head, int track, int sector, const char *buf, int length) { char membuf[1024]; int i; for (i = 0; i < length; i++) - sprintf(membuf + i*2, "%02x", (int) (uint8_t) buf[i]); + snprintf(membuf + i*2, 1024 - (i*2), "%02x", (int) (uint8_t) buf[i]); logerror("%s: head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf); } @@ -124,13 +88,11 @@ void legacy_floppy_image_device::floppy_drive_init() /* initialise flags */ m_flags = 0; m_index_pulse_callback = nullptr; - m_index_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(legacy_floppy_image_device::floppy_drive_index_callback),this)); + m_index_timer = timer_alloc(FUNC(legacy_floppy_image_device::floppy_drive_index_callback), this); m_idx = 0; floppy_drive_set_geometry(m_config->floppy_type); - /* initialise id index - not so important */ - m_id_index = 0; /* initialise track */ m_current_track = 0; @@ -138,8 +100,6 @@ void legacy_floppy_image_device::floppy_drive_init() m_rpm = 300; m_controller = nullptr; - - m_floppy_drive_type = FLOPPY_TYPE_REGULAR; } /* index pulses at rpm/60 Hz, and stays high 1/20th of time */ @@ -251,7 +211,7 @@ int legacy_floppy_image_device::floppy_drive_get_flag_state(int flag) void legacy_floppy_image_device::floppy_drive_seek(signed int signed_tracks) { - LOG(("seek from: %d delta: %d\n",m_current_track, signed_tracks)); + LOG("seek from: %d delta: %d\n", m_current_track, signed_tracks); /* update position */ m_current_track+=signed_tracks; @@ -267,83 +227,16 @@ void legacy_floppy_image_device::floppy_drive_seek(signed int signed_tracks) } /* set track 0 flag */ - m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE; + m_tk00 = (m_current_track == 0) ? 0 : 1; //m_out_tk00_func(m_tk00); /* clear disk changed flag */ - m_dskchg = ASSERT_LINE; + m_dskchg = 1; //m_out_dskchg_func(m_dskchg); /* inform disk image of step operation so it can cache information */ if (exists()) m_track = m_current_track; - - m_id_index = 0; -} - - -/* this is not accurate. But it will do for now */ -int legacy_floppy_image_device::floppy_drive_get_next_id(int side, chrn_id *id) -{ - int spt; - - /* get sectors per track */ - spt = flopimg_get_sectors_per_track(side); - - /* set index */ - if ((m_id_index==(spt-1)) || (spt==0)) - { - floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 1); - } - else - { - floppy_drive_set_flag_state(FLOPPY_DRIVE_INDEX, 0); - } - - /* get id */ - if (spt!=0) - { - flopimg_get_id_callback(id, m_id_index, side); - } - - m_id_index++; - if (spt!=0) - m_id_index %= spt; - else - m_id_index = 0; - - return (spt == 0) ? 0 : 1; -} - -void legacy_floppy_image_device::floppy_drive_read_track_data_info_buffer(int side, void *ptr, int *length ) -{ - if (exists()) - { - if (!m_floppy) - return; - - floppy_read_track_data(m_floppy, side, m_track, ptr, *length); - } -} - -void legacy_floppy_image_device::floppy_drive_write_track_data_info_buffer(int side, const void *ptr, int *length ) -{ - if (exists()) - { - if (!m_floppy) - return; - - floppy_write_track_data(m_floppy, side, m_track, ptr, *length); - } -} - -void legacy_floppy_image_device::floppy_drive_format_sector(int side, int sector_index,int c,int h, int r, int n, int filler) -{ - if (exists()) - { -/* if (m_interface_.format_sector) - m_interface_.format_sector(img, side, sector_index,c, h, r, n, filler);*/ - } } void legacy_floppy_image_device::floppy_drive_read_sector_data(int side, int index1, void *ptr, int length) @@ -385,28 +278,11 @@ void legacy_floppy_image_device::floppy_install_unload_proc(void (*proc)(device_ m_unload_proc = proc; } -/* set the callback for the index pulse */ -void legacy_floppy_image_device::floppy_drive_set_index_pulse_callback(void (*callback)(device_t *controller, device_t *img, int state)) -{ - m_index_pulse_callback = callback; -} - int legacy_floppy_image_device::floppy_drive_get_current_track() { return m_current_track; } -uint64_t legacy_floppy_image_device::floppy_drive_get_current_track_size(int head) -{ - int size = 0; - if (exists()) - { - size = floppy_get_track_size(m_floppy, head, m_current_track); - } - - return size; -} - void legacy_floppy_image_device::floppy_drive_set_rpm(float rpm) { m_rpm = rpm; @@ -417,52 +293,54 @@ void legacy_floppy_image_device::floppy_drive_set_controller(device_t *controlle m_controller = controller; } -image_init_result legacy_floppy_image_device::internal_floppy_device_load(bool is_create, int create_format, util::option_resolution *create_args) +std::error_condition legacy_floppy_image_device::internal_floppy_device_load(bool is_create, int create_format, util::option_resolution *create_args) { - floperr_t err; - const struct FloppyFormat *floppy_options; - int floppy_flags, i; + const struct FloppyFormat *floppy_options = m_config->formats; - device_image_interface *image = nullptr; - interface(image); /* figure out the floppy options */ - floppy_options = m_config->formats; - - if (is_create) + floperr_t err; + check_for_file(); + auto io = util::random_read_write_fill(image_core_file(), 0xff); + if (!io) + { + err = FLOPPY_ERROR_OUTOFMEMORY; + } + else if (is_create) { /* creating an image */ assert(create_format >= 0); - err = floppy_create((void *) image, &image_ioprocs, &floppy_options[create_format], create_args, &m_floppy); - if (err) - goto error; + err = floppy_create(std::move(io), &floppy_options[create_format], create_args, &m_floppy); } else { /* opening an image */ - floppy_flags = !is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; - err = floppy_open_choices((void *) image, &image_ioprocs, filetype(), floppy_options, floppy_flags, &m_floppy); - if (err) - goto error; - } - if (floppy_callbacks(m_floppy)->get_heads_per_disk && floppy_callbacks(m_floppy)->get_tracks_per_disk) - { - floppy_drive_set_geometry_absolute(floppy_get_tracks_per_disk(m_floppy),floppy_get_heads_per_disk(m_floppy)); + int const floppy_flags = !is_readonly() ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; + err = floppy_open_choices(std::move(io), filetype(), floppy_options, floppy_flags, &m_floppy); } - /* disk changed */ - m_dskchg = CLEAR_LINE; - // If we have one of our hacky load procs, call it - if (m_load_proc) - m_load_proc(*this, is_create); + if (!err) + { + if (floppy_callbacks(m_floppy)->get_heads_per_disk && floppy_callbacks(m_floppy)->get_tracks_per_disk) + { + floppy_drive_set_geometry_absolute(floppy_get_tracks_per_disk(m_floppy),floppy_get_heads_per_disk(m_floppy)); + } + /* disk changed */ + m_dskchg = CLEAR_LINE; - return image_init_result::PASS; + // If we have one of our hacky load procs, call it + if (m_load_proc) + m_load_proc(*this, is_create); -error: - for (i = 0; i < ARRAY_LENGTH(errmap); i++) + return std::error_condition(); + } + else { - if (err == errmap[i].ferr) - seterror(errmap[i].ierr, errmap[i].message); + for (int i = 0; i < std::size(errmap); i++) + { + if (err == errmap[i].ferr) + return errmap[i].ierr; + } + return image_error::UNSPECIFIED; } - return image_init_result::FAIL; } TIMER_CALLBACK_MEMBER( legacy_floppy_image_device::set_wpt ) @@ -471,115 +349,21 @@ TIMER_CALLBACK_MEMBER( legacy_floppy_image_device::set_wpt ) //m_out_wpt_func(param); } -legacy_floppy_image_device *floppy_get_device(running_machine &machine,int drive) -{ - switch(drive) { - case 0 : return machine.device<legacy_floppy_image_device>(FLOPPY_0); - case 1 : return machine.device<legacy_floppy_image_device>(FLOPPY_1); - case 2 : return machine.device<legacy_floppy_image_device>(FLOPPY_2); - case 3 : return machine.device<legacy_floppy_image_device>(FLOPPY_3); - } - return nullptr; -} - -int legacy_floppy_image_device::floppy_get_drive_type() -{ - return m_floppy_drive_type; -} - -void legacy_floppy_image_device::floppy_set_type(int ftype) -{ - m_floppy_drive_type = ftype; -} - -legacy_floppy_image_device *floppy_get_device_by_type(running_machine &machine,int ftype,int drive) -{ - int i; - int cnt = 0; - for (i=0;i<4;i++) { - legacy_floppy_image_device *disk = floppy_get_device(machine,i); - if (disk && disk->floppy_get_drive_type()==ftype) { - if (cnt==drive) { - return disk; - } - cnt++; - } - } - return nullptr; -} - -static int floppy_get_drive(device_t *image) -{ - int drive = -1; - if (strcmp(image->tag(), ":" FLOPPY_0) == 0) drive = 0; - if (strcmp(image->tag(), ":" FLOPPY_1) == 0) drive = 1; - if (strcmp(image->tag(), ":" FLOPPY_2) == 0) drive = 2; - if (strcmp(image->tag(), ":" FLOPPY_3) == 0) drive = 3; - return drive; -} - -int floppy_get_drive_by_type(legacy_floppy_image_device *image,int ftype) -{ - int i,drive =0; - for (i=0;i<4;i++) { - legacy_floppy_image_device *disk = floppy_get_device(image->machine(),i); - if (disk && disk->floppy_get_drive_type()==ftype) { - if (image==disk) { - return drive; - } - drive++; - } - } - return -1; -} - - -/* drive select 0 */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds0_w ) -{ - if (state == CLEAR_LINE) - m_active = (m_drive_id == 0); -} - -/* drive select 1 */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds1_w ) -{ - if (state == CLEAR_LINE) - m_active = (m_drive_id == 1); -} - -/* drive select 2 */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds2_w ) +/* drive select */ +void legacy_floppy_image_device::floppy_ds_w(int state) { - if (state == CLEAR_LINE) - m_active = (m_drive_id == 2); -} - -/* drive select 3 */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_ds3_w ) -{ - if (state == CLEAR_LINE) - m_active = (m_drive_id == 3); -} - -/* shortcut to write all four ds lines */ -WRITE8_MEMBER( legacy_floppy_image_device::floppy_ds_w ) -{ - floppy_ds0_w(BIT(data, 0)); - floppy_ds1_w(BIT(data, 1)); - floppy_ds2_w(BIT(data, 2)); - floppy_ds3_w(BIT(data, 3)); + m_active = (state == 0); } /* motor on, active low */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_mon_w ) +void legacy_floppy_image_device::floppy_mon_w(int state) { /* force off if there is no attached image */ if (!exists()) - state = ASSERT_LINE; + state = 1; /* off -> on */ - if (m_mon && state == CLEAR_LINE) + if (m_mon && state == 0) { m_idx = 0; floppy_drive_index_func(); @@ -593,18 +377,13 @@ WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_mon_w ) } /* direction */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_drtn_w ) +void legacy_floppy_image_device::floppy_drtn_w(int state) { m_drtn = state; } -/* write data */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtd_w ) -{ -} - /* step */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w ) +void legacy_floppy_image_device::floppy_stp_w(int state) { /* move head one track when going from high to low and write gate is high */ if (m_active && m_stp && state == CLEAR_LINE && m_wtg) @@ -617,7 +396,7 @@ WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w ) m_current_track--; /* are we at track 0 now? */ - m_tk00 = (m_current_track == 0) ? CLEAR_LINE : ASSERT_LINE; + m_tk00 = (m_current_track == 0) ? 0 : 1; } else { @@ -626,7 +405,7 @@ WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w ) m_current_track++; /* we can't be at track 0 here, so reset the line */ - m_tk00 = ASSERT_LINE; + m_tk00 = 1; } /* update track 0 line with new status */ @@ -641,44 +420,23 @@ WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_stp_w ) } /* write gate */ -WRITE_LINE_MEMBER( legacy_floppy_image_device::floppy_wtg_w ) +void legacy_floppy_image_device::floppy_wtg_w(int state) { m_wtg = state; } -/* write protect signal, active low */ -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_wpt_r ) -{ - return m_wpt; -} - /* track 0 detect */ -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_tk00_r ) +int legacy_floppy_image_device::floppy_tk00_r() { return m_tk00; } -/* disk changed */ -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_dskchg_r ) -{ - return m_dskchg; -} - -/* 2-sided disk */ -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_twosid_r ) -{ - if (m_floppy == nullptr) - return ASSERT_LINE; - else - return !floppy_get_heads_per_disk(m_floppy); -} - -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_index_r ) +int legacy_floppy_image_device::floppy_index_r() { return m_idx; } -READ_LINE_MEMBER( legacy_floppy_image_device::floppy_ready_r ) +int legacy_floppy_image_device::floppy_ready_r() { return !(floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) == FLOPPY_DRIVE_READY); } @@ -706,9 +464,7 @@ legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mco m_idx(0), m_tk00(0), m_wpt(0), - m_rdy(0), m_dskchg(0), - m_drive_id(-1), m_active(0), m_config(nullptr), m_flags(0), @@ -718,13 +474,11 @@ legacy_floppy_image_device::legacy_floppy_image_device(const machine_config &mco m_index_timer(nullptr), m_index_pulse_callback(nullptr), m_rpm(0.0f), - m_id_index(0), m_controller(nullptr), m_floppy(nullptr), m_track(0), m_load_proc(nullptr), - m_unload_proc(nullptr), - m_floppy_drive_type(0) + m_unload_proc(nullptr) { memset(&m_extension_list,0,sizeof(m_extension_list)); } @@ -745,11 +499,9 @@ void legacy_floppy_image_device::device_start() { floppy_drive_init(); - m_drive_id = floppy_get_drive(this); m_active = false; /* resolve callbacks */ - m_out_idx_func.resolve_safe(); //m_in_mon_func.resolve(m_config->in_mon_func, *this); //m_out_tk00_func.resolve(m_config->out_tk00_func, *this); //m_out_wpt_func.resolve(m_config->out_wpt_func, *this); @@ -757,19 +509,22 @@ void legacy_floppy_image_device::device_start() // m_out_dskchg_func.resolve(m_config->out_dskchg_func, *this); /* by default we are not write-protected */ - m_wpt = ASSERT_LINE; + m_wpt = 1; //m_out_wpt_func(m_wpt); /* not at track 0 */ - m_tk00 = ASSERT_LINE; + m_tk00 = 1; //m_out_tk00_func(m_tk00); /* motor off */ - m_mon = ASSERT_LINE; + m_mon = 1; /* disk changed */ m_dskchg = CLEAR_LINE; // m_out_dskchg_func(m_dskchg); + + /* write-protect callback */ + m_wpt_timer = timer_alloc(FUNC(legacy_floppy_image_device::set_wpt), this); } @@ -788,7 +543,8 @@ void legacy_floppy_image_device::device_config_complete() for (int i = 0; floppy_options && floppy_options[i].construct; i++) { // only add if creatable - if (floppy_options[i].param_guidelines) { + if (floppy_options[i].param_guidelines) + { // allocate a new format and append it to the list add_format(floppy_options[i].name, floppy_options[i].description, floppy_options[i].extensions, floppy_options[i].param_guidelines); } @@ -797,14 +553,19 @@ void legacy_floppy_image_device::device_config_complete() } } -image_init_result legacy_floppy_image_device::call_create(int format_type, util::option_resolution *format_options) +const software_list_loader &legacy_floppy_image_device::get_software_list_loader() const +{ + return image_software_list_loader::instance(); +} + +std::pair<std::error_condition, std::string> legacy_floppy_image_device::call_create(int format_type, util::option_resolution *format_options) { - return internal_floppy_device_load(true, format_type, format_options); + return std::make_pair(internal_floppy_device_load(true, format_type, format_options), std::string()); } -image_init_result legacy_floppy_image_device::call_load() +std::pair<std::error_condition, std::string> legacy_floppy_image_device::call_load() { - image_init_result retVal = internal_floppy_device_load(false, -1, nullptr); + std::error_condition retVal = internal_floppy_device_load(false, -1, nullptr); /* push disk halfway into drive */ m_wpt = CLEAR_LINE; @@ -814,13 +575,13 @@ image_init_result legacy_floppy_image_device::call_load() int next_wpt; if (!is_readonly()) - next_wpt = ASSERT_LINE; + next_wpt = 1; else - next_wpt = CLEAR_LINE; + next_wpt = 0; - machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), next_wpt); + m_wpt_timer->adjust(attotime::from_msec(250), next_wpt); - return retVal; + return std::make_pair(retVal, std::string()); } void legacy_floppy_image_device::call_unload() @@ -832,32 +593,32 @@ void legacy_floppy_image_device::call_unload() m_floppy = nullptr; /* disk changed */ - m_dskchg = CLEAR_LINE; + m_dskchg = 0; //m_out_dskchg_func(m_dskchg); /* pull disk halfway out of drive */ - m_wpt = CLEAR_LINE; + m_wpt = 0; //m_out_wpt_func(m_wpt); /* set timer for disk eject */ - machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), ASSERT_LINE); + m_wpt_timer->adjust(attotime::from_msec(250), 1); } -bool legacy_floppy_image_device::is_creatable() const +bool legacy_floppy_image_device::is_creatable() const noexcept { - int cnt = 0; - if (m_config != nullptr) + if (m_config) { const struct FloppyFormat *floppy_options = m_config->formats; - int i; - for ( i = 0; floppy_options[i].construct; i++ ) { - if(floppy_options[i].param_guidelines) cnt++; + for (int i = 0; floppy_options[i].construct; i++) + { + if (floppy_options[i].param_guidelines) + return true; } } - return (cnt>0) ? 1 : 0; + return false; } -const char *legacy_floppy_image_device::image_interface() const +const char *legacy_floppy_image_device::image_interface() const noexcept { return m_config->interface; } |