floppy: fix precision issue and missing cache clear on write

This commit is contained in:
Olivier Galibert 2021-01-16 21:50:55 +01:00
parent 16b5f50140
commit 0d4e5f7339
2 changed files with 10 additions and 8 deletions

View File

@ -195,7 +195,7 @@ floppy_image_device::floppy_image_device(const machine_config &mconfig, device_t
dir(0), stp(0), wtg(0), mon(0), ss(0), ds(-1), idx(0), wpt(0), rdy(0), dskchg(0),
ready(false),
rpm(0),
floppy_ratio_1(0),
angular_speed(0),
revolution_count(0),
cyl(0),
subcyl(0),
@ -288,7 +288,7 @@ void floppy_image_device::set_rpm(float _rpm)
rpm = _rpm;
rev_time = attotime::from_double(60/rpm);
floppy_ratio_1 = int(1000.0f*rpm/300.0f+0.5f);
angular_speed = rpm/300.0*2e8;
}
void floppy_image_device::setup_write(floppy_image_format_t *_output_format)
@ -364,7 +364,7 @@ void floppy_image_device::device_start()
save_item(NAME(dskchg));
save_item(NAME(ready));
save_item(NAME(rpm));
save_item(NAME(floppy_ratio_1));
save_item(NAME(angular_speed));
save_item(NAME(revolution_start_time));
save_item(NAME(rev_time));
save_item(NAME(revolution_count));
@ -626,12 +626,12 @@ void floppy_image_device::index_resync()
revolution_start_time += rev_time;
revolution_count++;
}
int position = (delta*floppy_ratio_1).as_ticks(1000000000/1000);
int position = int(delta.as_double()*angular_speed + 0.5);
int new_idx = position < 20000;
if(new_idx) {
attotime index_up_time = attotime::from_nsec((2000000*1000)/floppy_ratio_1);
attotime index_up_time = attotime::from_double(20000/angular_speed);
index_timer->adjust(index_up_time - delta);
} else
index_timer->adjust(rev_time - delta);
@ -813,7 +813,7 @@ uint32_t floppy_image_device::find_position(attotime &base, const attotime &when
base -= rev_time;
}
uint32_t res = (delta*floppy_ratio_1).as_ticks(1000000000/1000);
uint32_t res = uint32_t(delta.as_double()*angular_speed+0.5);
if (res >= 200000000) {
// Due to rounding errors in the previous operation,
// 'res' sometimes overflows 2E+8
@ -830,7 +830,7 @@ bool floppy_image_device::test_track_last_entry_warps(const std::vector<uint32_t
attotime floppy_image_device::position_to_time(const attotime &base, int position) const
{
return base + attotime::from_nsec((int64_t(position)*2000/floppy_ratio_1+1)/2);
return base + attotime::from_double(position/angular_speed);
}
void floppy_image_device::cache_fill_index(const std::vector<uint32_t> &buf, int &index, attotime &base)
@ -952,6 +952,7 @@ void floppy_image_device::write_flux(const attotime &start, const attotime &end,
if(!image || mon)
return;
image_dirty = true;
cache_clear();
attotime base;
int start_pos = find_position(base, start);

View File

@ -186,7 +186,8 @@ protected:
/* rotation per minute => gives index pulse frequency */
float rpm;
int floppy_ratio_1; // rpm/300*1000
/* angular speed, where a full circle is 2e8 */
double angular_speed;
attotime revolution_start_time, rev_time;
uint32_t revolution_count;