mirror of
https://github.com/holub/mame
synced 2025-05-24 14:56:21 +03:00
improved serial input emulation.
This commit is contained in:
parent
bba6893104
commit
678e9c4209
@ -27,14 +27,14 @@
|
||||
#include "devhelpr.h"
|
||||
|
||||
/***************************************************************************
|
||||
PARAMETERS
|
||||
PARAMETERS
|
||||
***************************************************************************/
|
||||
|
||||
#define TRACE_VIA 0
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
MACROS
|
||||
MACROS
|
||||
***************************************************************************/
|
||||
|
||||
/* Macros for PCR */
|
||||
@ -106,7 +106,7 @@
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE FUNCTIONS
|
||||
INLINE FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
inline void via6522_device::set_irq_line(int state)
|
||||
@ -134,13 +134,13 @@ UINT16 via6522_device::get_counter1_value()
|
||||
{
|
||||
UINT16 val;
|
||||
|
||||
if(m_t1_active)
|
||||
{
|
||||
val = time_to_cycles(m_t1->remaining()) - IFR_DELAY;
|
||||
if(m_t1_active)
|
||||
{
|
||||
val = time_to_cycles(m_t1->remaining()) - IFR_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
val = 0xffff - time_to_cycles(machine().time() - m_time1);
|
||||
else
|
||||
{
|
||||
val = 0xffff - time_to_cycles(machine().time() - m_time1);
|
||||
}
|
||||
|
||||
return val;
|
||||
@ -159,7 +159,7 @@ const device_type VIA6522 = &device_creator<via6522_device>;
|
||||
//-------------------------------------------------
|
||||
|
||||
via6522_device::via6522_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
|
||||
: device_t(mconfig, VIA6522, "6522 VIA", tag, owner, clock),
|
||||
: device_t(mconfig, VIA6522, "6522 VIA", tag, owner, clock),
|
||||
m_irq(CLEAR_LINE)
|
||||
{
|
||||
|
||||
@ -182,17 +182,17 @@ void via6522_device::device_config_complete()
|
||||
// or initialize to defaults if none provided
|
||||
else
|
||||
{
|
||||
memset(&m_in_a_cb, 0, sizeof(m_in_a_cb));
|
||||
memset(&m_in_b_cb, 0, sizeof(m_in_b_cb));
|
||||
memset(&m_in_ca1_cb, 0, sizeof(m_in_ca1_cb));
|
||||
memset(&m_in_cb1_cb, 0, sizeof(m_in_cb1_cb));
|
||||
memset(&m_in_ca2_cb, 0, sizeof(m_in_ca2_cb));
|
||||
memset(&m_in_cb2_cb, 0, sizeof(m_in_cb2_cb));
|
||||
memset(&m_out_a_cb, 0, sizeof(m_out_a_cb));
|
||||
memset(&m_out_b_cb, 0, sizeof(m_out_b_cb));
|
||||
memset(&m_out_ca2_cb, 0, sizeof(m_out_ca2_cb));
|
||||
memset(&m_out_cb2_cb, 0, sizeof(m_out_cb2_cb));
|
||||
memset(&m_irq_cb, 0, sizeof(m_irq_cb));
|
||||
memset(&m_in_a_cb, 0, sizeof(m_in_a_cb));
|
||||
memset(&m_in_b_cb, 0, sizeof(m_in_b_cb));
|
||||
memset(&m_in_ca1_cb, 0, sizeof(m_in_ca1_cb));
|
||||
memset(&m_in_cb1_cb, 0, sizeof(m_in_cb1_cb));
|
||||
memset(&m_in_ca2_cb, 0, sizeof(m_in_ca2_cb));
|
||||
memset(&m_in_cb2_cb, 0, sizeof(m_in_cb2_cb));
|
||||
memset(&m_out_a_cb, 0, sizeof(m_out_a_cb));
|
||||
memset(&m_out_b_cb, 0, sizeof(m_out_b_cb));
|
||||
memset(&m_out_ca2_cb, 0, sizeof(m_out_ca2_cb));
|
||||
memset(&m_out_cb2_cb, 0, sizeof(m_out_cb2_cb));
|
||||
memset(&m_irq_cb, 0, sizeof(m_irq_cb));
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,66 +203,66 @@ void via6522_device::device_config_complete()
|
||||
|
||||
void via6522_device::device_start()
|
||||
{
|
||||
m_in_a_func.resolve(m_in_a_cb, *this);
|
||||
m_in_b_func.resolve(m_in_b_cb, *this);
|
||||
m_in_ca1_func.resolve(m_in_ca1_cb, *this);
|
||||
m_in_cb1_func.resolve(m_in_cb1_cb, *this);
|
||||
m_in_ca2_func.resolve(m_in_ca2_cb, *this);
|
||||
m_in_cb2_func.resolve(m_in_cb2_cb, *this);
|
||||
m_out_a_func.resolve(m_out_a_cb, *this);
|
||||
m_out_b_func.resolve(m_out_b_cb, *this);
|
||||
m_out_ca1_func.resolve(m_out_ca1_cb, *this);
|
||||
m_out_cb1_func.resolve(m_out_cb1_cb, *this);
|
||||
m_out_ca2_func.resolve(m_out_ca2_cb, *this);
|
||||
m_out_cb2_func.resolve(m_out_cb2_cb, *this);
|
||||
m_irq_func.resolve(m_irq_cb, *this);
|
||||
m_in_a_func.resolve(m_in_a_cb, *this);
|
||||
m_in_b_func.resolve(m_in_b_cb, *this);
|
||||
m_in_ca1_func.resolve(m_in_ca1_cb, *this);
|
||||
m_in_cb1_func.resolve(m_in_cb1_cb, *this);
|
||||
m_in_ca2_func.resolve(m_in_ca2_cb, *this);
|
||||
m_in_cb2_func.resolve(m_in_cb2_cb, *this);
|
||||
m_out_a_func.resolve(m_out_a_cb, *this);
|
||||
m_out_b_func.resolve(m_out_b_cb, *this);
|
||||
m_out_ca1_func.resolve(m_out_ca1_cb, *this);
|
||||
m_out_cb1_func.resolve(m_out_cb1_cb, *this);
|
||||
m_out_ca2_func.resolve(m_out_ca2_cb, *this);
|
||||
m_out_cb2_func.resolve(m_out_cb2_cb, *this);
|
||||
m_irq_func.resolve(m_irq_cb, *this);
|
||||
|
||||
m_t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */
|
||||
m_t1lh = 0xb5; /* ports are not written by kernel! */
|
||||
m_t2ll = 0xff; /* taken from vice */
|
||||
m_t2lh = 0xff;
|
||||
m_time2 = m_time1 = machine().time();
|
||||
m_t1 = timer_alloc(TIMER_T1);
|
||||
m_t2 = timer_alloc(TIMER_T2);
|
||||
m_ca2_timer = timer_alloc(TIMER_CA2);
|
||||
m_shift_timer = timer_alloc(TIMER_SHIFT);
|
||||
m_t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */
|
||||
m_t1lh = 0xb5; /* ports are not written by kernel! */
|
||||
m_t2ll = 0xff; /* taken from vice */
|
||||
m_t2lh = 0xff;
|
||||
m_time2 = m_time1 = machine().time();
|
||||
m_t1 = timer_alloc(TIMER_T1);
|
||||
m_t2 = timer_alloc(TIMER_T2);
|
||||
m_ca2_timer = timer_alloc(TIMER_CA2);
|
||||
m_shift_timer = timer_alloc(TIMER_SHIFT);
|
||||
|
||||
/* Default clock is from CPU1 */
|
||||
if (clock() == 0)
|
||||
{
|
||||
{
|
||||
set_unscaled_clock(machine().firstcpu->clock());
|
||||
}
|
||||
}
|
||||
|
||||
/* save state register */
|
||||
save_item(NAME(m_in_a));
|
||||
save_item(NAME(m_in_ca1));
|
||||
save_item(NAME(m_in_ca2));
|
||||
save_item(NAME(m_out_a));
|
||||
save_item(NAME(m_out_ca2));
|
||||
save_item(NAME(m_ddr_a));
|
||||
save_item(NAME(m_in_b));
|
||||
save_item(NAME(m_in_cb1));
|
||||
save_item(NAME(m_in_cb2));
|
||||
save_item(NAME(m_out_b));
|
||||
save_item(NAME(m_out_cb2));
|
||||
save_item(NAME(m_ddr_b));
|
||||
save_item(NAME(m_t1cl));
|
||||
save_item(NAME(m_t1ch));
|
||||
save_item(NAME(m_t1ll));
|
||||
save_item(NAME(m_t1lh));
|
||||
save_item(NAME(m_t2cl));
|
||||
save_item(NAME(m_t2ch));
|
||||
save_item(NAME(m_t2ll));
|
||||
save_item(NAME(m_t2lh));
|
||||
save_item(NAME(m_sr));
|
||||
save_item(NAME(m_pcr));
|
||||
save_item(NAME(m_acr));
|
||||
save_item(NAME(m_ier));
|
||||
save_item(NAME(m_ifr));
|
||||
save_item(NAME(m_in_a));
|
||||
save_item(NAME(m_in_ca1));
|
||||
save_item(NAME(m_in_ca2));
|
||||
save_item(NAME(m_out_a));
|
||||
save_item(NAME(m_out_ca2));
|
||||
save_item(NAME(m_ddr_a));
|
||||
save_item(NAME(m_in_b));
|
||||
save_item(NAME(m_in_cb1));
|
||||
save_item(NAME(m_in_cb2));
|
||||
save_item(NAME(m_out_b));
|
||||
save_item(NAME(m_out_cb2));
|
||||
save_item(NAME(m_ddr_b));
|
||||
save_item(NAME(m_t1cl));
|
||||
save_item(NAME(m_t1ch));
|
||||
save_item(NAME(m_t1ll));
|
||||
save_item(NAME(m_t1lh));
|
||||
save_item(NAME(m_t2cl));
|
||||
save_item(NAME(m_t2ch));
|
||||
save_item(NAME(m_t2ll));
|
||||
save_item(NAME(m_t2lh));
|
||||
save_item(NAME(m_sr));
|
||||
save_item(NAME(m_pcr));
|
||||
save_item(NAME(m_acr));
|
||||
save_item(NAME(m_ier));
|
||||
save_item(NAME(m_ifr));
|
||||
save_item(NAME(m_irq));
|
||||
save_item(NAME(m_t1_active));
|
||||
save_item(NAME(m_t2_active));
|
||||
save_item(NAME(m_shift_counter));
|
||||
save_item(NAME(m_t1_active));
|
||||
save_item(NAME(m_t2_active));
|
||||
save_item(NAME(m_shift_counter));
|
||||
}
|
||||
|
||||
|
||||
@ -272,32 +272,32 @@ void via6522_device::device_start()
|
||||
|
||||
void via6522_device::device_reset()
|
||||
{
|
||||
m_in_a = 0;
|
||||
m_in_ca1 = 0;
|
||||
m_in_ca2 = 0;
|
||||
m_out_a = 0;
|
||||
m_out_ca2 = 0;
|
||||
m_ddr_a = 0;
|
||||
m_in_b = 0;
|
||||
m_in_cb1 = 0;
|
||||
m_in_cb2 = 0;
|
||||
m_out_b = 0;
|
||||
m_out_cb2 = 0;
|
||||
m_ddr_b = 0;
|
||||
m_in_a = 0;
|
||||
m_in_ca1 = 0;
|
||||
m_in_ca2 = 0;
|
||||
m_out_a = 0;
|
||||
m_out_ca2 = 0;
|
||||
m_ddr_a = 0;
|
||||
m_in_b = 0;
|
||||
m_in_cb1 = 0;
|
||||
m_in_cb2 = 0;
|
||||
m_out_b = 0;
|
||||
m_out_cb2 = 0;
|
||||
m_ddr_b = 0;
|
||||
|
||||
m_t1cl = 0;
|
||||
m_t1ch = 0;
|
||||
m_t2cl = 0;
|
||||
m_t2ch = 0;
|
||||
m_t1cl = 0;
|
||||
m_t1ch = 0;
|
||||
m_t2cl = 0;
|
||||
m_t2ch = 0;
|
||||
|
||||
m_sr = 0;
|
||||
m_pcr = 0;
|
||||
m_acr = 0;
|
||||
m_ier = 0;
|
||||
m_ifr = 0;
|
||||
m_t1_active = 0;
|
||||
m_t2_active = 0;
|
||||
m_shift_counter = 0;
|
||||
m_sr = 0;
|
||||
m_pcr = 0;
|
||||
m_acr = 0;
|
||||
m_ier = 0;
|
||||
m_ifr = 0;
|
||||
m_t1_active = 0;
|
||||
m_t2_active = 0;
|
||||
m_shift_counter = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -309,15 +309,15 @@ void via6522_device::set_int(int data)
|
||||
{
|
||||
m_ifr |= data;
|
||||
if (TRACE_VIA)
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: IFR = %02X\n", machine().describe_context(), tag(), m_ifr);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ier & m_ifr)
|
||||
{
|
||||
{
|
||||
m_ifr |= INT_ANY;
|
||||
set_irq_line(ASSERT_LINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -330,14 +330,14 @@ void via6522_device::clear_int(int data)
|
||||
m_ifr = (m_ifr & ~data) & 0x7f;
|
||||
|
||||
if (TRACE_VIA)
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: IFR = %02X\n", machine().describe_context(), tag(), m_ifr);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ifr & m_ier)
|
||||
{
|
||||
{
|
||||
m_ifr |= INT_ANY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
set_irq_line(CLEAR_LINE);
|
||||
@ -367,52 +367,82 @@ void via6522_device::shift()
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
|
||||
if (m_shift_counter)
|
||||
{
|
||||
{
|
||||
if (SO_O2_CONTROL(m_acr)) {
|
||||
m_shift_timer->adjust(cycles_to_time(2));
|
||||
} else {
|
||||
m_shift_timer->adjust(cycles_to_time((m_t2ll + 2)*2));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
{
|
||||
{
|
||||
set_int(INT_SR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SO_EXT_CONTROL(m_acr))
|
||||
{
|
||||
m_out_cb2 = (m_sr >> 7) & 1;
|
||||
m_sr = (m_sr << 1) | m_out_cb2;
|
||||
m_out_cb2 = (m_sr >> 7) & 1;
|
||||
m_sr = (m_sr << 1) | m_out_cb2;
|
||||
|
||||
m_out_cb2_func(m_out_cb2);
|
||||
m_out_cb2_func(m_out_cb2);
|
||||
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
|
||||
if (m_shift_counter == 0)
|
||||
if (m_shift_counter == 0)
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
{
|
||||
set_int(INT_SR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SI_EXT_CONTROL(m_acr))
|
||||
|
||||
if (SI_O2_CONTROL(m_acr) || SI_T2_CONTROL(m_acr))
|
||||
{
|
||||
if (!m_in_cb2_func.isnull())
|
||||
{
|
||||
m_in_cb2 = m_in_cb2_func();
|
||||
}
|
||||
|
||||
m_sr = (m_sr << 1) | (m_in_cb2 & 1);
|
||||
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
|
||||
if (m_shift_counter == 0)
|
||||
if (!m_in_cb2_func.isnull())
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
m_in_cb2 = m_in_cb2_func();
|
||||
}
|
||||
|
||||
m_sr = (m_sr << 1) | (m_in_cb2 & 1);
|
||||
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
|
||||
if (m_shift_counter)
|
||||
{
|
||||
if (SI_O2_CONTROL(m_acr)) {
|
||||
m_shift_timer->adjust(cycles_to_time(2));
|
||||
} else {
|
||||
m_shift_timer->adjust(cycles_to_time((m_t2ll + 2)*2));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
{
|
||||
set_int(INT_SR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SI_EXT_CONTROL(m_acr))
|
||||
{
|
||||
if (!m_in_cb2_func.isnull())
|
||||
{
|
||||
m_in_cb2 = m_in_cb2_func();
|
||||
}
|
||||
|
||||
m_sr = (m_sr << 1) | (m_in_cb2 & 1);
|
||||
|
||||
m_shift_counter = (m_shift_counter + 1) % 8;
|
||||
|
||||
if (m_shift_counter == 0)
|
||||
{
|
||||
if (!(m_ifr & INT_SR))
|
||||
{
|
||||
set_int(INT_SR);
|
||||
}
|
||||
@ -432,45 +462,45 @@ void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int para
|
||||
|
||||
// t1 timeout
|
||||
case TIMER_T1:
|
||||
if (T1_CONTINUOUS (m_acr))
|
||||
{
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
m_out_b ^= 0x80;
|
||||
}
|
||||
m_t1->adjust(cycles_to_time(TIMER1_VALUE + IFR_DELAY));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
m_out_b |= 0x80;
|
||||
}
|
||||
m_t1_active = 0;
|
||||
m_time1 = machine().time();
|
||||
}
|
||||
if (m_ddr_b)
|
||||
if (T1_CONTINUOUS (m_acr))
|
||||
{
|
||||
UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff);
|
||||
m_out_b_func(0, write_data);
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
m_out_b ^= 0x80;
|
||||
}
|
||||
m_t1->adjust(cycles_to_time(TIMER1_VALUE + IFR_DELAY));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
m_out_b |= 0x80;
|
||||
}
|
||||
m_t1_active = 0;
|
||||
m_time1 = machine().time();
|
||||
}
|
||||
if (m_ddr_b)
|
||||
{
|
||||
UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff);
|
||||
m_out_b_func(0, write_data);
|
||||
}
|
||||
|
||||
if (!(m_ifr & INT_T1))
|
||||
{
|
||||
if (!(m_ifr & INT_T1))
|
||||
{
|
||||
set_int(INT_T1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
// t2 timeout
|
||||
case TIMER_T2:
|
||||
m_t2_active = 0;
|
||||
m_time2 = machine().time();
|
||||
m_t2_active = 0;
|
||||
m_time2 = machine().time();
|
||||
|
||||
if (!(m_ifr & INT_T2))
|
||||
{
|
||||
if (!(m_ifr & INT_T2))
|
||||
{
|
||||
set_int(INT_T2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case TIMER_CA2:
|
||||
m_out_ca2_func(1);
|
||||
@ -490,21 +520,21 @@ READ8_MEMBER( via6522_device::read )
|
||||
offset &= 0xf;
|
||||
|
||||
switch (offset)
|
||||
{
|
||||
case VIA_PB:
|
||||
{
|
||||
case VIA_PB:
|
||||
/* update the input */
|
||||
if (PB_LATCH_ENABLE(m_acr) == 0)
|
||||
if (PB_LATCH_ENABLE(m_acr) == 0)
|
||||
{
|
||||
if (m_ddr_b != 0xff)
|
||||
{
|
||||
if (!m_in_b_func.isnull())
|
||||
{
|
||||
{
|
||||
m_in_b = m_in_b_func(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -512,29 +542,29 @@ READ8_MEMBER( via6522_device::read )
|
||||
|
||||
/* combine input and output values, hold DDRB bit 7 high if T1_SET_PB7 */
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
{
|
||||
val = (m_out_b & (m_ddr_b | 0x80)) | (m_in_b & ~(m_ddr_b | 0x80));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
val = (m_out_b & m_ddr_b) + (m_in_b & ~m_ddr_b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_PA:
|
||||
case VIA_PA:
|
||||
/* update the input */
|
||||
if (PA_LATCH_ENABLE(m_acr) == 0)
|
||||
{
|
||||
if (m_ddr_a != 0xff)
|
||||
{
|
||||
if (!m_in_a_func.isnull())
|
||||
{
|
||||
{
|
||||
m_in_a = m_in_a_func(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +574,7 @@ READ8_MEMBER( via6522_device::read )
|
||||
CLR_PA_INT();
|
||||
|
||||
/* If CA2 is configured as output and in pulse or handshake mode,
|
||||
CA2 is set now */
|
||||
CA2 is set now */
|
||||
if (CA2_PULSE_OUTPUT(m_pcr))
|
||||
{
|
||||
/* call the CA2 output function */
|
||||
@ -569,116 +599,116 @@ READ8_MEMBER( via6522_device::read )
|
||||
|
||||
break;
|
||||
|
||||
case VIA_PANH:
|
||||
case VIA_PANH:
|
||||
/* update the input */
|
||||
if (PA_LATCH_ENABLE(m_acr) == 0)
|
||||
{
|
||||
if (!m_in_a_func.isnull())
|
||||
{
|
||||
{
|
||||
m_in_a = m_in_a_func(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* combine input and output values */
|
||||
val = (m_out_a & m_ddr_a) + (m_in_a & ~m_ddr_a);
|
||||
break;
|
||||
|
||||
case VIA_DDRB:
|
||||
case VIA_DDRB:
|
||||
val = m_ddr_b;
|
||||
break;
|
||||
|
||||
case VIA_DDRA:
|
||||
case VIA_DDRA:
|
||||
val = m_ddr_a;
|
||||
break;
|
||||
|
||||
case VIA_T1CL:
|
||||
case VIA_T1CL:
|
||||
clear_int(INT_T1);
|
||||
val = get_counter1_value() & 0xFF;
|
||||
break;
|
||||
|
||||
case VIA_T1CH:
|
||||
case VIA_T1CH:
|
||||
val = get_counter1_value() >> 8;
|
||||
break;
|
||||
|
||||
case VIA_T1LL:
|
||||
case VIA_T1LL:
|
||||
val = m_t1ll;
|
||||
break;
|
||||
|
||||
case VIA_T1LH:
|
||||
case VIA_T1LH:
|
||||
val = m_t1lh;
|
||||
break;
|
||||
|
||||
case VIA_T2CL:
|
||||
case VIA_T2CL:
|
||||
clear_int(INT_T2);
|
||||
if (m_t2_active)
|
||||
{
|
||||
{
|
||||
val = time_to_cycles(m_t2->remaining()) & 0xff;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (T2_COUNT_PB6(m_acr))
|
||||
{
|
||||
{
|
||||
val = m_t2cl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
val = (0x10000 - (time_to_cycles(machine().time() - m_time2) & 0xffff) - 1) & 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_T2CH:
|
||||
case VIA_T2CH:
|
||||
if (m_t2_active)
|
||||
{
|
||||
{
|
||||
val = time_to_cycles(m_t2->remaining()) >> 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (T2_COUNT_PB6(m_acr))
|
||||
{
|
||||
{
|
||||
val = m_t2ch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
val = (0x10000 - (time_to_cycles(machine().time() - m_time2) & 0xffff) - 1) >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_SR:
|
||||
case VIA_SR:
|
||||
val = m_sr;
|
||||
m_shift_counter=0;
|
||||
clear_int(INT_SR);
|
||||
if (SO_O2_CONTROL(m_acr))
|
||||
if (SI_O2_CONTROL(m_acr))
|
||||
{
|
||||
m_shift_timer->adjust(cycles_to_time(2));
|
||||
}
|
||||
if (SO_T2_CONTROL(m_acr))
|
||||
if (SI_T2_CONTROL(m_acr))
|
||||
{
|
||||
m_shift_timer->adjust(cycles_to_time((m_t2ll + 2)*2));
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_PCR:
|
||||
case VIA_PCR:
|
||||
val = m_pcr;
|
||||
break;
|
||||
|
||||
case VIA_ACR:
|
||||
case VIA_ACR:
|
||||
val = m_acr;
|
||||
break;
|
||||
|
||||
case VIA_IER:
|
||||
case VIA_IER:
|
||||
val = m_ier | 0x80;
|
||||
break;
|
||||
|
||||
case VIA_IFR:
|
||||
case VIA_IFR:
|
||||
val = m_ifr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -692,8 +722,8 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
offset &=0x0f;
|
||||
|
||||
switch (offset)
|
||||
{
|
||||
case VIA_PB:
|
||||
{
|
||||
case VIA_PB:
|
||||
if (T1_SET_PB7(m_acr))
|
||||
m_out_b = (m_out_b & 0x80) | (data & 0x7f);
|
||||
else
|
||||
@ -708,7 +738,7 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
CLR_PB_INT();
|
||||
|
||||
/* If CB2 is configured as output and in pulse or handshake mode,
|
||||
CB2 is set now */
|
||||
CB2 is set now */
|
||||
if (CB2_AUTO_HS(m_pcr))
|
||||
{
|
||||
if (m_out_cb2)
|
||||
@ -722,7 +752,7 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_PA:
|
||||
case VIA_PA:
|
||||
m_out_a = data;
|
||||
|
||||
if (m_ddr_a)
|
||||
@ -757,7 +787,7 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
|
||||
break;
|
||||
|
||||
case VIA_PANH:
|
||||
case VIA_PANH:
|
||||
m_out_a = data;
|
||||
|
||||
if (m_ddr_a)
|
||||
@ -768,10 +798,10 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
|
||||
break;
|
||||
|
||||
case VIA_DDRB:
|
||||
/* EHC 03/04/2000 - If data direction changed, present output on the lines */
|
||||
if ( data != m_ddr_b )
|
||||
{
|
||||
case VIA_DDRB:
|
||||
/* EHC 03/04/2000 - If data direction changed, present output on the lines */
|
||||
if ( data != m_ddr_b )
|
||||
{
|
||||
m_ddr_b = data;
|
||||
|
||||
//if (m_ddr_b)
|
||||
@ -782,10 +812,10 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_DDRA:
|
||||
/* EHC 03/04/2000 - If data direction changed, present output on the lines */
|
||||
if ( data != m_ddr_a )
|
||||
{
|
||||
case VIA_DDRA:
|
||||
/* EHC 03/04/2000 - If data direction changed, present output on the lines */
|
||||
if ( data != m_ddr_a )
|
||||
{
|
||||
m_ddr_a = data;
|
||||
|
||||
//if (m_ddr_a)
|
||||
@ -796,17 +826,17 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_T1CL:
|
||||
case VIA_T1LL:
|
||||
case VIA_T1CL:
|
||||
case VIA_T1LL:
|
||||
m_t1ll = data;
|
||||
break;
|
||||
|
||||
case VIA_T1LH:
|
||||
m_t1lh = data;
|
||||
clear_int(INT_T1);
|
||||
break;
|
||||
m_t1lh = data;
|
||||
clear_int(INT_T1);
|
||||
break;
|
||||
|
||||
case VIA_T1CH:
|
||||
case VIA_T1CH:
|
||||
m_t1ch = m_t1lh = data;
|
||||
m_t1cl = m_t1ll;
|
||||
|
||||
@ -826,11 +856,11 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
m_t1_active = 1;
|
||||
break;
|
||||
|
||||
case VIA_T2CL:
|
||||
case VIA_T2CL:
|
||||
m_t2ll = data;
|
||||
break;
|
||||
|
||||
case VIA_T2CH:
|
||||
case VIA_T2CH:
|
||||
m_t2ch = m_t2lh = data;
|
||||
m_t2cl = m_t2ll;
|
||||
|
||||
@ -849,7 +879,7 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_SR:
|
||||
case VIA_SR:
|
||||
m_sr = data;
|
||||
m_shift_counter=0;
|
||||
clear_int(INT_SR);
|
||||
@ -863,13 +893,13 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_PCR:
|
||||
case VIA_PCR:
|
||||
m_pcr = data;
|
||||
|
||||
if (TRACE_VIA)
|
||||
{
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: PCR = %02X\n", machine().describe_context(), tag(), data);
|
||||
}
|
||||
}
|
||||
|
||||
if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ m_out_ca2)
|
||||
{
|
||||
@ -884,20 +914,20 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
}
|
||||
break;
|
||||
|
||||
case VIA_ACR:
|
||||
case VIA_ACR:
|
||||
{
|
||||
UINT16 counter1 = get_counter1_value();
|
||||
m_acr = data;
|
||||
if (T1_SET_PB7(m_acr))
|
||||
{
|
||||
if (m_t1_active)
|
||||
{
|
||||
{
|
||||
m_out_b &= ~0x80;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
m_out_b |= 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
//if (m_ddr_b)
|
||||
{
|
||||
@ -915,13 +945,13 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
|
||||
case VIA_IER:
|
||||
if (data & 0x80)
|
||||
{
|
||||
{
|
||||
m_ier |= data & 0x7f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
m_ier &= ~(data & 0x7f);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ifr & INT_ANY)
|
||||
{
|
||||
@ -943,12 +973,12 @@ WRITE8_MEMBER( via6522_device::write )
|
||||
|
||||
case VIA_IFR:
|
||||
if (data & INT_ANY)
|
||||
{
|
||||
{
|
||||
data = 0x7f;
|
||||
}
|
||||
}
|
||||
clear_int(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -960,7 +990,7 @@ WRITE_LINE_MEMBER( via6522_device::write_ca1 )
|
||||
{
|
||||
/* handle the active transition */
|
||||
if (state != m_in_ca1)
|
||||
{
|
||||
{
|
||||
if (TRACE_VIA)
|
||||
logerror("%s:6522VIA chip %s: CA1 = %02X\n", machine().describe_context(), tag(), state);
|
||||
|
||||
@ -969,19 +999,19 @@ WRITE_LINE_MEMBER( via6522_device::write_ca1 )
|
||||
if (PA_LATCH_ENABLE(m_acr))
|
||||
{
|
||||
if (!m_in_a_func.isnull())
|
||||
{
|
||||
{
|
||||
m_in_a = m_in_a_func(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
}
|
||||
|
||||
set_int(INT_CA1);
|
||||
|
||||
/* CA2 is configured as output and in pulse or handshake mode,
|
||||
CA2 is cleared now */
|
||||
CA2 is cleared now */
|
||||
if (CA2_AUTO_HS(m_pcr))
|
||||
{
|
||||
if (!m_out_ca2)
|
||||
@ -996,7 +1026,7 @@ WRITE_LINE_MEMBER( via6522_device::write_ca1 )
|
||||
}
|
||||
|
||||
m_in_ca1 = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1008,7 +1038,7 @@ WRITE_LINE_MEMBER( via6522_device::write_ca2 )
|
||||
{
|
||||
/* CA2 is in input mode */
|
||||
if (CA2_INPUT(m_pcr))
|
||||
{
|
||||
{
|
||||
/* the new state has caused a transition */
|
||||
if (m_in_ca2 != state)
|
||||
{
|
||||
@ -1021,7 +1051,7 @@ WRITE_LINE_MEMBER( via6522_device::write_ca2 )
|
||||
/* set the new value for CA2 */
|
||||
m_in_ca2 = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1033,29 +1063,29 @@ WRITE_LINE_MEMBER( via6522_device::write_cb1 )
|
||||
{
|
||||
/* handle the active transition */
|
||||
if (state != m_in_cb1)
|
||||
{
|
||||
{
|
||||
if ((CB1_LOW_TO_HIGH(m_pcr) && state) || (CB1_HIGH_TO_LOW(m_pcr) && !state))
|
||||
{
|
||||
if (PB_LATCH_ENABLE(m_acr))
|
||||
{
|
||||
if (!m_in_b_func.isnull())
|
||||
{
|
||||
{
|
||||
m_in_b = m_in_b_func(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
{
|
||||
logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", machine().describe_context(), tag());
|
||||
}
|
||||
}
|
||||
if (SO_EXT_CONTROL(m_acr) || SI_EXT_CONTROL(m_acr))
|
||||
{
|
||||
{
|
||||
shift();
|
||||
}
|
||||
}
|
||||
|
||||
set_int(INT_CB1);
|
||||
|
||||
/* CB2 is configured as output and in pulse or handshake mode,
|
||||
CB2 is cleared now */
|
||||
CB2 is cleared now */
|
||||
if (CB2_AUTO_HS(m_pcr))
|
||||
{
|
||||
if (!m_out_cb2)
|
||||
@ -1069,7 +1099,7 @@ WRITE_LINE_MEMBER( via6522_device::write_cb1 )
|
||||
}
|
||||
}
|
||||
m_in_cb1 = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1081,7 +1111,7 @@ WRITE_LINE_MEMBER( via6522_device::write_cb2 )
|
||||
{
|
||||
/* CB2 is in input mode */
|
||||
if (CB2_INPUT(m_pcr))
|
||||
{
|
||||
{
|
||||
/* the new state has caused a transition */
|
||||
if (m_in_cb2 != state)
|
||||
{
|
||||
@ -1094,5 +1124,5 @@ WRITE_LINE_MEMBER( via6522_device::write_cb2 )
|
||||
/* set the new value for CB2 */
|
||||
m_in_cb2 = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user