fix cur_reg being overwritten

This commit is contained in:
Michaël Banaan Ananas 2013-11-30 18:39:03 +00:00
parent d762aef09f
commit 8057efb522
2 changed files with 33 additions and 33 deletions

View File

@ -41,8 +41,8 @@ void ymz770_device::device_start()
channels[i].decoder = new mpeg_audio(rom_base, mpeg_audio::AMM, false, 0); channels[i].decoder = new mpeg_audio(rom_base, mpeg_audio::AMM, false, 0);
} }
// register for save states
save_item(NAME(cur_reg)); save_item(NAME(m_cur_reg));
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
save_item(NAME(channels[i].phrase), i); save_item(NAME(channels[i].phrase), i);
@ -132,8 +132,7 @@ void ymz770_device::sound_stream_update(sound_stream &stream, stream_sample_t **
channels[ch].seqdelay = 32 - 1; channels[ch].seqdelay = 32 - 1;
break; break;
default: default:
cur_reg = reg; internal_reg_write(reg, data);
internal_reg_write(1, data);
break; break;
} }
} }
@ -147,7 +146,7 @@ void ymz770_device::sound_stream_update(sound_stream &stream, stream_sample_t **
} }
else else
{ {
retry: retry:
if (channels[ch].last_block) if (channels[ch].last_block)
{ {
if (channels[ch].control & 1) if (channels[ch].control & 1)
@ -190,7 +189,7 @@ void ymz770_device::sound_stream_update(sound_stream &stream, stream_sample_t **
} }
//------------------------------------------------- //-------------------------------------------------
// read - read from the chip's registers and internal RAM // read - read from the chip's registers
//------------------------------------------------- //-------------------------------------------------
READ8_MEMBER( ymz770_device::read ) READ8_MEMBER( ymz770_device::read )
@ -198,22 +197,13 @@ READ8_MEMBER( ymz770_device::read )
return 0; return 0;
} }
void ymz770_device::internal_reg_write(int offset, UINT8 data) void ymz770_device::internal_reg_write(UINT8 reg, UINT8 data)
{ {
if (!offset) if (reg >= 0x40 && reg <= 0x5f)
{ {
cur_reg = data; int voice = reg >> 2 & 0x07;
return;
}
if (cur_reg >= 0x40 && cur_reg <= 0x5f) switch (reg & 0x03)
{
cur_reg -= 0x40;
int voice = cur_reg / 4;
int reg = cur_reg % 4;
switch (reg)
{ {
case 0: case 0:
channels[voice].phrase = data; channels[voice].phrase = data;
@ -247,11 +237,11 @@ void ymz770_device::internal_reg_write(int offset, UINT8 data)
break; break;
} }
} }
else if (cur_reg >= 0x80) else if (reg >= 0x80)
{ {
int voice = (cur_reg & 0x70)>>4; int voice = reg >> 4 & 0x07;
int reg = cur_reg & 0x0f;
switch (reg) switch (reg & 0x0f)
{ {
case 0: case 0:
channels[voice].sequence = data; channels[voice].sequence = data;
@ -269,18 +259,29 @@ void ymz770_device::internal_reg_write(int offset, UINT8 data)
{ {
channels[voice].is_seq_playing = false; channels[voice].is_seq_playing = false;
} }
channels[voice].seqcontrol = data; channels[voice].seqcontrol = data;
break; break;
default:
break;
} }
} }
} }
//------------------------------------------------- //-------------------------------------------------
// write - write to the chip's registers and internal RAM // write - write to the chip's registers
//------------------------------------------------- //-------------------------------------------------
WRITE8_MEMBER( ymz770_device::write ) WRITE8_MEMBER( ymz770_device::write )
{ {
if (offset & 1)
{
m_stream->update(); m_stream->update();
internal_reg_write(offset, data); internal_reg_write(m_cur_reg, data);
}
else
{
m_cur_reg = data;
}
} }

View File

@ -55,7 +55,6 @@ class ymz770_device : public device_t, public device_sound_interface
UINT8 seqdelay; UINT8 seqdelay;
UINT8 *seqdata; UINT8 *seqdata;
bool is_seq_playing; bool is_seq_playing;
}; };
@ -76,10 +75,10 @@ protected:
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
void internal_reg_write(int offset, UINT8 data); void internal_reg_write(UINT8 reg, UINT8 data);
// data // data
UINT8 cur_reg; UINT8 m_cur_reg;
UINT8 *rom_base; UINT8 *rom_base;
int rom_size; int rom_size;