Skip to content

Commit

Permalink
wd_fdc: reset the contents of data_reg when the sync is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pnp2084 committed Oct 22, 2022
1 parent 6c15d70 commit f5eeb26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions src/devices/machine/wd_fdc.cpp
Expand Up @@ -1683,6 +1683,14 @@ bool wd_fdc_device_base::read_one_bit(const attotime &limit)
return false;
}

void wd_fdc_device_base::reset_data_sync()
{
cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;

cur_live.data_reg = bitswap<8>(cur_live.shift_reg, 14, 12, 10, 8, 6, 4, 2, 0);
}

bool wd_fdc_device_base::write_one_bit(const attotime &limit)
{
bool bit = cur_live.shift_reg & 0x8000;
Expand Down Expand Up @@ -1779,15 +1787,13 @@ void wd_fdc_device_base::live_run(attotime limit)

if(!dden && cur_live.shift_reg == 0x4489) {
cur_live.crc = 0x443b;
cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;
reset_data_sync();
cur_live.state = READ_HEADER_BLOCK_HEADER;
}

if(dden && cur_live.shift_reg == 0xf57e) {
cur_live.crc = 0xef21;
cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;
reset_data_sync();
if(main_state == READ_ID)
cur_live.state = READ_ID_BLOCK_TO_DMA;
else
Expand Down Expand Up @@ -1907,8 +1913,7 @@ void wd_fdc_device_base::live_run(attotime limit)

if(cur_live.bit_counter >= 28*16 && cur_live.shift_reg == 0x4489) {
cur_live.crc = 0x443b;
cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;
reset_data_sync();
cur_live.state = READ_DATA_BLOCK_HEADER;
}
} else {
Expand All @@ -1925,6 +1930,8 @@ void wd_fdc_device_base::live_run(attotime limit)
cur_live.shift_reg == 0xf56e ? 0xafa5 :
0xbf84;

reset_data_sync();

if(extended_ddam) {
if(!(cur_live.data_reg & 1))
status |= S_DDM;
Expand All @@ -1933,8 +1940,6 @@ void wd_fdc_device_base::live_run(attotime limit)
} else if((cur_live.data_reg & 0xfe) == 0xf8)
status |= S_DDM;

cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;
cur_live.state = READ_SECTOR_DATA;
}
}
Expand Down Expand Up @@ -2033,7 +2038,10 @@ void wd_fdc_device_base::live_run(attotime limit)
// FM resyncs
&& !(dden && (cur_live.shift_reg == 0xf57e // FM IDAM
|| cur_live.shift_reg == 0xf56f // FM DAM
|| cur_live.shift_reg == 0xf56a)) // FM DDAM
|| cur_live.shift_reg == 0xf56a // FM DDAM
|| cur_live.shift_reg == 0xf56b // FM DDAM
|| cur_live.shift_reg == 0xf56e // FM DDAM
|| cur_live.shift_reg == 0xf56f)) // FM DDAM
)
break;

Expand All @@ -2050,8 +2058,7 @@ void wd_fdc_device_base::live_run(attotime limit)
// MZ: TI99 "DISkASSEMBLER" copy protection requires a threshold of 8
bool output_byte = cur_live.bit_counter > 8;

cur_live.data_separator_phase = false;
cur_live.bit_counter = 0;
reset_data_sync();

if(output_byte) {
live_delay(READ_TRACK_DATA_BYTE);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/machine/wd_fdc.h
Expand Up @@ -357,7 +357,7 @@ class wd_fdc_device_base : public device_t {
void live_run(attotime limit = attotime::never);
bool read_one_bit(const attotime &limit);
bool write_one_bit(const attotime &limit);

void reset_data_sync();
void live_write_raw(uint16_t raw);
void live_write_mfm(uint8_t mfm);
void live_write_fm(uint8_t fm);
Expand Down

0 comments on commit f5eeb26

Please sign in to comment.