small cleanup

This commit is contained in:
Michaël Banaan Ananas 2014-08-14 10:21:26 +00:00
parent 6420e3263d
commit dd7d8e1761
4 changed files with 80 additions and 79 deletions

View File

@ -1032,6 +1032,7 @@ void i80186_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int p
t->int_timer->adjust(attotime::never, which);
break;
}
default:
break;
}
@ -1052,12 +1053,12 @@ void i80186_cpu_device::inc_timer(int which)
struct timer_state *t = &m_timer[which];
t->count++;
if(t->control & 2)
if (t->control & 2)
{
if(t->count == (t->active_count ? t->maxB : t->maxA))
if (t->count == (t->active_count ? t->maxB : t->maxA))
device_timer(*t->int_timer, which, which, NULL);
}
else if(t->count == t->maxA)
else if (t->count == t->maxA)
device_timer(*t->int_timer, which, which, NULL);
}
@ -1088,10 +1089,12 @@ void i80186_cpu_device::internal_timer_update(int which,int new_count,int new_ma
internal_timer_sync(which);
update_int_timer = 1;
}
t->maxA = new_maxA;
if (new_maxA == 0)
{
new_maxA = 0x10000;
new_maxA = 0x10000;
}
}
@ -1108,11 +1111,10 @@ void i80186_cpu_device::internal_timer_update(int which,int new_count,int new_ma
if (new_maxB == 0)
{
new_maxB = 0x10000;
new_maxB = 0x10000;
}
}
/* handle control changes */
if (new_control != -1)
{
@ -1367,7 +1369,7 @@ READ16_MEMBER(i80186_cpu_device::internal_port_r)
case 0x30:
if (LOG_PORTS) logerror("%05X:read 80186 Timer %d count\n", pc(), (offset - 0x28) / 4);
which = (offset - 0x28) / 4;
if (!(offset & 1))
if (ACCESSING_BITS_0_7)
internal_timer_sync(which);
return m_timer[which].count;
@ -1466,7 +1468,7 @@ READ16_MEMBER(i80186_cpu_device::internal_port_r)
WRITE16_MEMBER(i80186_cpu_device::internal_port_w)
{
int which;
switch (offset)
{
case 0x11:
@ -1670,9 +1672,9 @@ WRITE16_MEMBER(i80186_cpu_device::internal_port_w)
{
UINT32 newmap = (data & 0xfff) << 8;
UINT32 oldmap = (m_reloc & 0xfff) << 8;
if(!(data & 0x1000) || ((data & 0x1000) && (m_reloc & 0x1000)))
if (!(data & 0x1000) || ((data & 0x1000) && (m_reloc & 0x1000)))
m_program->unmap_readwrite(oldmap, oldmap + 0xff);
if(data & 0x1000) // TODO: make work with 80188 if needed
if (data & 0x1000) // TODO: make work with 80188 if needed
m_program->install_readwrite_handler(newmap, newmap + 0xff, read16_delegate(FUNC(i80186_cpu_device::internal_port_r), this), write16_delegate(FUNC(i80186_cpu_device::internal_port_w), this));
}
m_reloc = data;

View File

@ -41,7 +41,7 @@ enum
#define LOG1(msg) do { if (VERBOSE >= 1) logerror msg; } while (0)
#define LOG2(msg) do { if (VERBOSE >= 2) logerror msg; } while (0)
#define CYCLES_NEVER ((UINT32) -1)
#define CYCLES_NEVER (0xffffffff)
const device_type PIT8253 = &device_creator<pit8253_device>;
@ -56,7 +56,7 @@ pit8253_device::pit8253_device(const machine_config &mconfig, const char *tag, d
m_out1_handler(*this),
m_out2_handler(*this)
{
for(int i = 0; i < ARRAY_LENGTH(m_timers); ++i)
for (int i = 0; i < PIT8253_MAX_TIMER; i++)
{
m_timers[i].gate = 1;
m_timers[i].phase = 0;
@ -73,7 +73,7 @@ pit8253_device::pit8253_device(const machine_config &mconfig, device_type type,
m_out1_handler(*this),
m_out2_handler(*this)
{
for(int i = 0; i < ARRAY_LENGTH(m_timers); ++i)
for (int i = 0; i < PIT8253_MAX_TIMER; i++)
{
m_timers[i].gate = 1;
m_timers[i].phase = 0;
@ -129,7 +129,6 @@ void pit8253_device::device_start()
save_item(NAME(timer->latched_status), timerno);
save_item(NAME(timer->null_count), timerno);
save_item(NAME(timer->phase), timerno);
save_item(NAME(timer->cycles_to_output), timerno);
save_item(NAME(timer->last_updated), timerno);
save_item(NAME(timer->clock), timerno);
}
@ -158,7 +157,6 @@ void pit8253_device::device_reset()
timer->latched_count = 0;
timer->latched_status = 0;
timer->null_count = 1;
timer->cycles_to_output = CYCLES_NEVER;
timer->last_updated = machine().time();
@ -215,16 +213,16 @@ INLINE UINT32 decimal_from_bcd(UINT16 val)
static UINT32 adjusted_count(int bcd, UINT16 val)
{
if (bcd == 0)
return val == 0 ? 0x10000 : val;
return val == 0 ? 10000 : decimal_from_bcd(val);
if (!bcd)
return (val == 0) ? 0x10000 : val;
return (val == 0) ? 10000 : decimal_from_bcd(val);
}
/* This function subtracts 1 from timer->value "cycles" times, taking into
account binary or BCD operation, and wrapping around from 0 to 0xFFFF or
0x9999 as necessary. */
void pit8253_device::decrease_counter_value(pit8253_timer *timer, UINT64 cycles)
void pit8253_device::decrease_counter_value(pit8253_timer *timer, INT64 cycles)
{
UINT16 value;
UINT8 units, tens, hundreds, thousands;
@ -250,7 +248,7 @@ void pit8253_device::decrease_counter_value(pit8253_timer *timer, UINT64 cycles)
cycles -= units;
units = (10 - cycles % 10) % 10;
cycles =(cycles + 9) / 10; /* the +9 is so we get a carry if cycles%10 wasn't 0 */
cycles = (cycles + 9) / 10; /* the +9 is so we get a carry if cycles%10 wasn't 0 */
if (cycles <= tens)
{
tens -= cycles;
@ -269,7 +267,7 @@ void pit8253_device::decrease_counter_value(pit8253_timer *timer, UINT64 cycles)
{
cycles -= hundreds;
hundreds = (10 - cycles % 10) % 10;
cycles=(cycles + 9) / 10;
cycles = (cycles + 9) / 10;
thousands = (10 + thousands - cycles % 10) % 10;
}
}
@ -321,7 +319,7 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles)
UINT32 adjusted_value;
int bcd = CTRL_BCD(timer->control);
int mode = CTRL_MODE(timer->control);
int cycles_to_output = 0;
UINT32 cycles_to_output = CYCLES_NEVER;
LOG2(("pit8253: simulate2(): simulating %d cycles for %d in mode %d, bcd = %d, phase = %d, gate = %d, output %d, value = 0x%04x\n",
(int)elapsed_cycles, timer->index, mode, bcd, timer->phase, pit8253_gate(timer), timer->output, timer->value));
@ -503,7 +501,7 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles)
{
if (elapsed_cycles + 1 >= adjusted_value)
{
/* Coounter hits 1, output goes low */
/* Counter hits 1, output goes low */
timer->phase = 3;
set_output(timer, 0);
}
@ -527,7 +525,7 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles)
switch (timer->phase)
{
case 1: cycles_to_output = 1; break;
default: cycles_to_output = (timer->value == 1 ? 1 : (adjusted_count(bcd, timer->value) - 1));
default: cycles_to_output = (timer->value == 1) ? 1 : (adjusted_count(bcd, timer->value) - 1); break;
}
}
break;
@ -604,7 +602,8 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles)
while ((timer->phase == 2 && elapsed_cycles >= ((adjusted_value + 1) >> 1)) ||
(timer->phase == 3 && elapsed_cycles >= (adjusted_value >> 1)));
decrease_counter_value(timer, elapsed_cycles << 1);
decrease_counter_value(timer, elapsed_cycles * 2);
switch (timer->phase)
{
case 1: cycles_to_output = 1; break;
@ -692,7 +691,6 @@ void pit8253_device::simulate2(pit8253_timer *timer, INT64 elapsed_cycles)
break;
}
timer->cycles_to_output = cycles_to_output;
if (cycles_to_output == CYCLES_NEVER || timer->clockin == 0)
{
timer->updatetimer->adjust(attotime::never, timer->index);
@ -730,9 +728,8 @@ void pit8253_device::simulate(pit8253_timer *timer, INT64 elapsed_cycles)
{
if (elapsed_cycles > 0)
simulate2(timer, elapsed_cycles);
else
if (timer->clockin)
timer->updatetimer->adjust(attotime::from_hz(timer->clockin), timer->index);
else if (timer->clockin)
timer->updatetimer->adjust(attotime::from_hz(timer->clockin), timer->index);
}
@ -741,9 +738,9 @@ void pit8253_device::update(pit8253_timer *timer)
{
/* With the 82C54's maximum clockin of 10MHz, 64 bits is nearly 60,000
years of time. Should be enough for now. */
attotime now = machine().time();
attotime now = machine().time();
attotime elapsed_time = now - timer->last_updated;
INT64 elapsed_cycles = elapsed_time.as_double() * timer->clockin;
INT64 elapsed_cycles = elapsed_time.as_double() * timer->clockin;
LOG1(("pit8253: update(): timer %d, %" I64FMT "d elapsed_cycles\n", timer->index, elapsed_cycles));
@ -811,7 +808,7 @@ READ8_MEMBER( pit8253_device::read )
if (timer->latched_count != 0)
{
/* Read back latched count */
data = (timer->latch >> (timer->rmsb != 0 ? 8 : 0)) & 0xff;
data = (timer->latch >> (timer->rmsb ? 8 : 0)) & 0xff;
timer->rmsb = 1 - timer->rmsb;
--timer->latched_count;
}
@ -840,7 +837,7 @@ READ8_MEMBER( pit8253_device::read )
case 3:
/* read bits 0-7 first, then 8-15 */
data = (value >> (timer->rmsb != 0 ? 8 : 0)) & 0xff;
data = (value >> (timer->rmsb ? 8 : 0)) & 0xff;
timer->rmsb = 1 - timer->rmsb;
break;
}
@ -892,16 +889,15 @@ void pit8253_device::readback(pit8253_timer *timer, int command)
if ((command & 1) == 0)
{
/* readback status command */
if (timer->latched_status == 0)
if (!timer->latched_status)
{
timer->status = (timer->control & 0x3f) | (timer->output != 0 ? 0x80 : 0) | (timer->null_count != 0 ? 0x40 : 0);
timer->status = (timer->control & 0x3f) | ((timer->output != 0) ? 0x80 : 0) | (timer->null_count ? 0x40 : 0);
timer->latched_status = 1;
}
timer->latched_status = 1;
}
/* Experimentally determined: the read latch command seems to have no
effect if we're halfway through a 16-bit read */
if ((command & 2) == 0 && timer->rmsb == 0)
if ((command & 2) == 0 && !timer->rmsb)
{
/* readback count command */
@ -984,7 +980,8 @@ WRITE8_MEMBER( pit8253_device::write )
/* Experimentally verified: this command does not affect the mode control register */
readback(timer, 1);
}
else {
else
{
LOG1(("pit8253: write(): timer=%d bytes=%d mode=%d bcd=%d\n", (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7, data & 1));
timer->control = (data & 0x3f);
@ -1039,7 +1036,7 @@ WRITE8_MEMBER( pit8253_device::write )
case 3:
/* read/write bits 0-7 first, then 8-15 */
if (timer->wmsb != 0)
if (timer->wmsb)
{
/* check if we should compensate for not being on a cycle boundary */
if (middle_of_a_cycle)

View File

@ -62,17 +62,15 @@ struct pit8253_timer
UINT8 control; /* 6-bit control byte */
UINT8 status; /* status byte - 8254 only */
UINT8 lowcount; /* LSB of new counter value for 16-bit writes */
INT32 rmsb; /* 1 = Next read is MSB of 16-bit value */
INT32 wmsb; /* 1 = Next write is MSB of 16-bit value */
INT32 output; /* 0 = low, 1 = high */
int rmsb; /* 1 = Next read is MSB of 16-bit value */
int wmsb; /* 1 = Next write is MSB of 16-bit value */
int output; /* 0 = low, 1 = high */
INT32 gate; /* gate input (0 = low, 1 = high) */
INT32 latched_count; /* number of bytes of count latched */
INT32 latched_status; /* 1 = status latched (8254 only) */
INT32 null_count; /* 1 = mode control or count written, 0 = count loaded */
INT32 phase; /* see phase definition tables in simulate2(), below */
UINT32 cycles_to_output; /* cycles until output callback called */
int gate; /* gate input (0 = low, 1 = high) */
int latched_count; /* number of bytes of count latched */
int latched_status; /* 1 = status latched (8254 only) */
int null_count; /* 1 = mode control or count written, 0 = count loaded */
int phase; /* see phase definition tables in simulate2(), below */
};
class pit8253_device : public device_t
@ -125,7 +123,7 @@ protected:
private:
int pit8253_gate(pit8253_timer *timer);
void decrease_counter_value(pit8253_timer *timer, UINT64 cycles);
void decrease_counter_value(pit8253_timer *timer, INT64 cycles);
void load_counter_value(pit8253_timer *timer);
void set_output(pit8253_timer *timer, int output);
void simulate2(pit8253_timer *timer, INT64 elapsed_cycles);

View File

@ -124,9 +124,9 @@ WRITE_LINE_MEMBER(leland_80186_sound_device::i80186_tmr0_w)
WRITE_LINE_MEMBER(leland_80186_sound_device::i80186_tmr1_w)
{
if(state)
if (state)
{
if(m_ext_active && (m_ext_start < m_ext_stop))
if (m_ext_active && (m_ext_start < m_ext_stop))
{
m_dac_sample[7] = (m_ext_base[m_ext_start] << 8) - 0x8000;
m_ext_start++;
@ -248,7 +248,7 @@ void leland_80186_sound_device::device_start()
m_audiocpu = downcast<i80186_cpu_device *>(machine().device("audiocpu"));
/* determine which sound hardware is installed */
if(m_type == TYPE_WSF)
if (m_type == TYPE_WSF)
m_ext_base = machine().root_device().memregion("dac")->base();
m_dac_timer = timer_alloc();
@ -257,9 +257,10 @@ void leland_80186_sound_device::device_start()
void leland_80186_sound_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
INT32 out = 0;
for(int i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
out += m_dac_sample[i] * m_dac_volume[i];
m_dac->write(out>>10);
m_dac->write(out >> 10);
}
void leland_80186_sound_device::device_reset()
@ -324,11 +325,12 @@ wsf_80186_sound_device::wsf_80186_sound_device(const machine_config &mconfig, co
WRITE16_MEMBER(leland_80186_sound_device::peripheral_ctrl)
{
switch(offset)
switch (offset)
{
case 2:
m_peripheral = data;
break;
case 4:
{
UINT32 temp = (m_peripheral & 0xffc0) << 4;
@ -343,6 +345,7 @@ WRITE16_MEMBER(leland_80186_sound_device::peripheral_ctrl)
}
break;
}
default:
break;
}
@ -494,7 +497,7 @@ WRITE16_MEMBER( leland_80186_sound_device::dac_w )
/* handle value changes */
if (ACCESSING_BITS_0_7)
{
m_dac_sample[which] = (data << 8) - 0x8000;
m_dac_sample[which] = (data << 8 & 0xff00) - 0x8000;
m_clock_active &= ~(1<<which);
}
@ -535,6 +538,9 @@ WRITE16_MEMBER( leland_80186_sound_device::ataxx_dac_control )
if (ACCESSING_BITS_0_7)
dac_w(space, 1, data, mem_mask);
return;
default:
break;
}
/* if we have a YM2151 (and an external DAC), handle those offsets */
@ -565,6 +571,9 @@ WRITE16_MEMBER( leland_80186_sound_device::ataxx_dac_control )
m_ext_stop <<= 4;
if (LOG_EXTERN) logerror("External DAC stop = %05X\n", m_ext_stop);
return;
default:
break;
}
}
logerror("%05X:Unexpected peripheral write %d/%02X = %02X\n", m_audiocpu->device_t::safe_pc(), 5, offset, data);
@ -601,27 +610,25 @@ READ16_MEMBER( leland_80186_sound_device::peripheral_r )
return main_to_sound_comm_r(space, offset, mem_mask);
case 2:
if(mem_mask == 0xff00)
return 0xffff;
return m_pit0->read(space, offset & 3);
if (mem_mask != 0xff00)
return m_pit0->read(space, offset & 3);
break;
case 3:
if (m_type <= TYPE_REDLINE)
{
if(mem_mask == 0xff00)
return 0xffff;
return m_pit1->read(space, offset & 3);
if (mem_mask != 0xff00)
return m_pit1->read(space, offset & 3);
}
else if(m_type == TYPE_WSF)
else if (m_type == TYPE_WSF)
return m_ymsnd->read(space, offset);
break;
case 4:
if (m_type == TYPE_REDLINE)
{
if(mem_mask == 0xff00)
return 0xffff;
return m_pit2->read(space, offset & 3);
if (mem_mask != 0xff00)
return m_pit2->read(space, offset & 3);
}
else
logerror("%05X:Unexpected peripheral read %d/%02X\n", m_audiocpu->device_t::safe_pc(), select, offset*2);
@ -647,17 +654,15 @@ WRITE16_MEMBER( leland_80186_sound_device::peripheral_w )
break;
case 2:
if(mem_mask == 0xff00)
return;
m_pit0->write(space, offset & 3, data);
if (mem_mask != 0xff00)
m_pit0->write(space, offset & 3, data);
break;
case 3:
if (m_type <= TYPE_REDLINE)
{
if(mem_mask == 0xff00)
return;
m_pit1->write(space, offset & 3, data);
if (mem_mask != 0xff00)
m_pit1->write(space, offset & 3, data);
}
else if(m_type == TYPE_WSF)
m_ymsnd->write(space, offset, data);
@ -666,11 +671,10 @@ WRITE16_MEMBER( leland_80186_sound_device::peripheral_w )
case 4:
if (m_type == TYPE_REDLINE)
{
if(mem_mask == 0xff00)
return;
m_pit2->write(space, offset & 3, data);
if (mem_mask != 0xff00)
m_pit2->write(space, offset & 3, data);
}
else if(mem_mask == 0xffff)
else if (mem_mask == 0xffff)
{
m_dac_sample[6] = (data << 6) - 0x8000;
m_clock_active &= ~(1<<6);
@ -678,7 +682,7 @@ WRITE16_MEMBER( leland_80186_sound_device::peripheral_w )
break;
case 5: /* Ataxx/WSF/Indy Heat only */
if(m_type > TYPE_REDLINE)
if (m_type > TYPE_REDLINE)
ataxx_dac_control(space, offset, data, mem_mask);
break;