Skip to content

Commit

Permalink
use templates for tlcs900 ports
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Sep 14, 2024
1 parent 000cf3b commit 75cbe79
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 694 deletions.
318 changes: 94 additions & 224 deletions src/devices/cpu/tlcs900/tmp95c061.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,12 @@ DEFINE_DEVICE_TYPE(TMP95C061, tmp95c061_device, "tmp95c061", "Toshiba TMP95C061"

tmp95c061_device::tmp95c061_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
tlcs900h_device(mconfig, TMP95C061, tag, owner, clock),
m_port1_read(*this, 0),
m_port1_write(*this),
m_port2_write(*this),
m_port5_read(*this, 0),
m_port5_write(*this),
m_port6_read(*this, 0),
m_port6_write(*this),
m_port7_read(*this, 0),
m_port7_write(*this),
m_port8_read(*this, 0),
m_port8_write(*this),
m_port9_read(*this, 0),
m_porta_read(*this, 0),
m_porta_write(*this),
m_portb_read(*this, 0),
m_portb_write(*this),
m_an_read(*this, 0),
m_port_latch{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_port_control{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_port_function{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_port_read(*this, 0),
m_port_write(*this),
m_port_latch{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_port_control{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_port_function{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
m_trun(0),
m_t8_reg{ 0, 0, 0, 0 },
m_t8_mode{ 0, 0 },
Expand Down Expand Up @@ -67,37 +53,90 @@ tmp95c061_device::tmp95c061_device(const machine_config &mconfig, const char *ta
{
}

template <Port P>
void tmp95c061_device::port_w(uint8_t data)
{
m_port_latch[P] = data;
m_port_write[P](0, data, 0xff);
}

template <Port P>
uint8_t tmp95c061_device::port_r()
{
return m_port_read[P](0);
}

template <Port P>
void tmp95c061_device::port_cr_w(uint8_t data)
{
m_port_control[P] = data;
}

template <Port P>
void tmp95c061_device::port_fc_w(uint8_t data)
{
m_port_function[P] = data;
}

template<>
void tmp95c061_device::port_w <PORT_A> (uint8_t data)
{
m_port_latch[PORT_A] = data;
update_porta();
}

template<>
void tmp95c061_device::port_cr_w <PORT_A> (uint8_t data)
{
m_port_control[PORT_A] = data;
update_porta();
}

template<>
void tmp95c061_device::port_fc_w <PORT_A> (uint8_t data)
{
m_port_function[PORT_A] = data;
update_porta();
}

void tmp95c061_device::update_porta()
{
int fc = (m_to1 << 2) | (m_to3 << 3);

m_port_write[PORT_A](0, ((fc & m_port_function[PORT_A]) | (m_port_latch[PORT_A] & ~m_port_function[PORT_A])) & m_port_control[PORT_A], 0xff);
}

void tmp95c061_device::internal_mem(address_map &map)
{
map(0x000001, 0x000001).rw(FUNC(tmp95c061_device::p1_r), FUNC(tmp95c061_device::p1_w));
map(0x000004, 0x000004).w(FUNC(tmp95c061_device::p1cr_w));
map(0x000006, 0x000006).rw(FUNC(tmp95c061_device::p2_r), FUNC(tmp95c061_device::p2_w));
map(0x000009, 0x000009).w(FUNC(tmp95c061_device::p2fc_w));
map(0x00000d, 0x00000d).rw(FUNC(tmp95c061_device::p5_r), FUNC(tmp95c061_device::p5_w));
map(0x000010, 0x000010).w(FUNC(tmp95c061_device::p5cr_w));
map(0x000011, 0x000011).w(FUNC(tmp95c061_device::p5fc_w));
map(0x000012, 0x000012).rw(FUNC(tmp95c061_device::p6_r), FUNC(tmp95c061_device::p6_w));
map(0x000013, 0x000013).rw(FUNC(tmp95c061_device::p7_r), FUNC(tmp95c061_device::p7_w));
map(0x000015, 0x000015).w(FUNC(tmp95c061_device::p6fc_w));
map(0x000016, 0x000016).w(FUNC(tmp95c061_device::p7cr_w));
map(0x000017, 0x000017).w(FUNC(tmp95c061_device::p7fc_w));
map(0x000018, 0x000018).rw(FUNC(tmp95c061_device::p8_r), FUNC(tmp95c061_device::p8_w));
map(0x000019, 0x000019).r(FUNC(tmp95c061_device::p9_r));
map(0x00001a, 0x00001a).w(FUNC(tmp95c061_device::p8cr_w));
map(0x00001b, 0x00001b).w(FUNC(tmp95c061_device::p8fc_w));
map(0x00001e, 0x00001e).rw(FUNC(tmp95c061_device::pa_r), FUNC(tmp95c061_device::pa_w));
map(0x00001f, 0x00001f).rw(FUNC(tmp95c061_device::pb_r), FUNC(tmp95c061_device::pb_w));
map(0x000001, 0x000001).rw(FUNC(tmp95c061_device::port_r<PORT_1>), FUNC(tmp95c061_device::port_w<PORT_1>));
map(0x000004, 0x000004).w(FUNC(tmp95c061_device::port_cr_w<PORT_1>));
map(0x000006, 0x000006).rw(FUNC(tmp95c061_device::port_r<PORT_2>), FUNC(tmp95c061_device::port_w<PORT_2>));
map(0x000009, 0x000009).w(FUNC(tmp95c061_device::port_fc_w<PORT_2>));
map(0x00000d, 0x00000d).rw(FUNC(tmp95c061_device::port_r<PORT_5>), FUNC(tmp95c061_device::port_w<PORT_5>));
map(0x000010, 0x000010).w(FUNC(tmp95c061_device::port_cr_w<PORT_5>));
map(0x000011, 0x000011).w(FUNC(tmp95c061_device::port_fc_w<PORT_5>));
map(0x000012, 0x000012).rw(FUNC(tmp95c061_device::port_r<PORT_6>), FUNC(tmp95c061_device::port_w<PORT_7>));
map(0x000013, 0x000013).rw(FUNC(tmp95c061_device::port_r<PORT_7>), FUNC(tmp95c061_device::port_w<PORT_7>));
map(0x000015, 0x000015).w(FUNC(tmp95c061_device::port_fc_w<PORT_6>));
map(0x000016, 0x000016).w(FUNC(tmp95c061_device::port_cr_w<PORT_7>));
map(0x000017, 0x000017).w(FUNC(tmp95c061_device::port_fc_w<PORT_7>));
map(0x000018, 0x000018).rw(FUNC(tmp95c061_device::port_r<PORT_8>), FUNC(tmp95c061_device::port_w<PORT_8>));
map(0x000019, 0x000019).r(FUNC(tmp95c061_device::port_r<PORT_9>));
map(0x00001a, 0x00001a).w(FUNC(tmp95c061_device::port_cr_w<PORT_8>));
map(0x00001b, 0x00001b).w(FUNC(tmp95c061_device::port_fc_w<PORT_8>));
map(0x00001e, 0x00001e).rw(FUNC(tmp95c061_device::port_r<PORT_A>), FUNC(tmp95c061_device::port_w<PORT_A>));
map(0x00001f, 0x00001f).rw(FUNC(tmp95c061_device::port_r<PORT_B>), FUNC(tmp95c061_device::port_w<PORT_B>));
map(0x000020, 0x000020).rw(FUNC(tmp95c061_device::trun_r), FUNC(tmp95c061_device::trun_w));
map(0x000022, 0x000023).w(FUNC(tmp95c061_device::treg01_w));
map(0x000024, 0x000024).w(FUNC(tmp95c061_device::t01mod_w));
map(0x000025, 0x000025).rw(FUNC(tmp95c061_device::tffcr_r), FUNC(tmp95c061_device::tffcr_w));
map(0x000026, 0x000027).w(FUNC(tmp95c061_device::treg23_w));
map(0x000028, 0x000028).w(FUNC(tmp95c061_device::t23mod_w));
map(0x000029, 0x000029).rw(FUNC(tmp95c061_device::trdc_r), FUNC(tmp95c061_device::trdc_w));
map(0x00002c, 0x00002c).w(FUNC(tmp95c061_device::pacr_w));
map(0x00002d, 0x00002d).w(FUNC(tmp95c061_device::pafc_w));
map(0x00002e, 0x00002e).w(FUNC(tmp95c061_device::pbcr_w));
map(0x00002f, 0x00002f).w(FUNC(tmp95c061_device::pbfc_w));
map(0x00002c, 0x00002c).w(FUNC(tmp95c061_device::port_cr_w<PORT_A>));
map(0x00002d, 0x00002d).w(FUNC(tmp95c061_device::port_fc_w<PORT_A>));
map(0x00002e, 0x00002e).w(FUNC(tmp95c061_device::port_cr_w<PORT_B>));
map(0x00002f, 0x00002f).w(FUNC(tmp95c061_device::port_fc_w<PORT_B>));
map(0x000030, 0x000033).w(FUNC(tmp95c061_device::treg45_w));
map(0x000034, 0x000037).r(FUNC(tmp95c061_device::cap12_r));
map(0x000038, 0x000038).rw(FUNC(tmp95c061_device::t4mod_r), FUNC(tmp95c061_device::t4mod_w));
Expand Down Expand Up @@ -207,18 +246,18 @@ void tmp95c061_device::device_reset()
m_timer_change[2] = 0;
m_timer_change[3] = 0;

m_port_latch[1] = 0x00;
m_port_latch[2] = 0xff;
m_port_latch[5] = 0x3d;
m_port_latch[6] = 0x3b;
m_port_latch[7] = 0xff;
m_port_latch[8] = 0x3f;
m_port_latch[0xa] = 0x0f;
m_port_latch[0xb] = 0xff;
std::fill_n(&m_port_control[0], 0xc, 0x00);
std::fill_n(&m_port_function[0], 0xc, 0x00);
m_port_control[0xa] = 0x0c; // HACK ngpc needs this but should be zero
m_port_function[0xa] = 0x0c; // HACK ngpc needs this but should be zero
m_port_latch[PORT_1] = 0x00;
m_port_latch[PORT_2] = 0xff;
m_port_latch[PORT_5] = 0x3d;
m_port_latch[PORT_6] = 0x3b;
m_port_latch[PORT_7] = 0xff;
m_port_latch[PORT_8] = 0x3f;
m_port_latch[PORT_A] = 0x0f;
m_port_latch[PORT_B] = 0xff;
std::fill_n(&m_port_control[0], NUM_PORTS, 0x00);
std::fill_n(&m_port_function[0], NUM_PORTS, 0x00);
m_port_control[PORT_A] = 0x0c; // HACK ngpc needs this but should be zero
m_port_function[PORT_A] = 0x0c; // HACK ngpc needs this but should be zero
m_trun = 0x00;
std::fill_n(&m_t8_mode[0], 2, 0x00);
m_t8_invert = 0xcc;
Expand Down Expand Up @@ -833,7 +872,7 @@ void tmp95c061_device::execute_set_input(int input, int level)
break;

case TLCS900_INT4:
if ( ! ( m_port_control[0xb] & 0x01 ) )
if ( ! ( m_port_control[PORT_B] & 0x01 ) )
{
if ( m_level[TLCS900_INT4] == CLEAR_LINE && level == ASSERT_LINE )
{
Expand All @@ -844,7 +883,7 @@ void tmp95c061_device::execute_set_input(int input, int level)
break;

case TLCS900_INT5:
if ( ! ( m_port_control[0xb] & 0x02 ) )
if ( ! ( m_port_control[PORT_B] & 0x02 ) )
{
if ( m_level[TLCS900_INT5] == CLEAR_LINE && level == ASSERT_LINE )
{
Expand All @@ -868,175 +907,6 @@ void tmp95c061_device::execute_set_input(int input, int level)
m_check_irqs = 1;
}


uint8_t tmp95c061_device::p1_r()
{
return m_port1_read(0);
}

void tmp95c061_device::p1_w(uint8_t data)
{
m_port_latch[1] = data;
m_port1_write(0, data, 0xff);
}

void tmp95c061_device::p1cr_w(uint8_t data)
{
m_port_control[1] = data;
}

uint8_t tmp95c061_device::p2_r()
{
return m_port_latch[2];
}

void tmp95c061_device::p2_w(uint8_t data)
{
m_port_latch[2] = data;
m_port2_write(0, data, 0xff);
}

void tmp95c061_device::p2fc_w(uint8_t data)
{
m_port_control[2] = data;
}

uint8_t tmp95c061_device::p5_r()
{
return m_port5_read(0);
}

void tmp95c061_device::p5_w(uint8_t data)
{
m_port_latch[5] = data;
m_port5_write(0, data, 0xff);
}

void tmp95c061_device::p5cr_w(uint8_t data)
{
m_port_control[5] = data;
}

void tmp95c061_device::p5fc_w(uint8_t data)
{
m_port_function[5] = data;
}

uint8_t tmp95c061_device::p6_r()
{
return m_port6_read(0);
}

void tmp95c061_device::p6_w(uint8_t data)
{
m_port_latch[6] = data;
m_port6_write(0, data, 0xff);
}

void tmp95c061_device::p6fc_w(uint8_t data)
{
m_port_function[6] = data;
}

uint8_t tmp95c061_device::p7_r()
{
return m_port7_read(0);
}

void tmp95c061_device::p7_w(uint8_t data)
{
m_port_latch[7] = data;
m_port7_write(0, data, 0xff);
}

void tmp95c061_device::p7cr_w(uint8_t data)
{
m_port_control[7] = data;
}

void tmp95c061_device::p7fc_w(uint8_t data)
{
m_port_function[7] = data;
}

uint8_t tmp95c061_device::p8_r()
{
return m_port8_read(0);
}

void tmp95c061_device::p8_w(uint8_t data)
{
m_port_latch[8] = data;
m_port8_write(0, data, 0xff);
}

void tmp95c061_device::p8cr_w(uint8_t data)
{
m_port_control[8] = data;
}

void tmp95c061_device::p8fc_w(uint8_t data)
{
m_port_function[8] = data;
}

uint8_t tmp95c061_device::p9_r()
{
return m_port9_read(0);
}

uint8_t tmp95c061_device::pa_r()
{
return m_porta_read(0);
}

void tmp95c061_device::pa_w(uint8_t data)
{
m_port_latch[0xa] = data;
update_porta();
}

void tmp95c061_device::pacr_w(uint8_t data)
{
m_port_control[0xa] = data;
update_porta();
}

void tmp95c061_device::pafc_w(uint8_t data)
{
m_port_function[0xa] = data;
update_porta();
}

void tmp95c061_device::update_porta()
{
int fc = (m_to1 << 2) | (m_to3 << 3);

m_porta_write(0, ((fc & m_port_function[0xa]) | (m_port_latch[0xa] & ~m_port_function[0xa])) & m_port_control[0xa], 0xff);
}

uint8_t tmp95c061_device::pb_r()
{
return m_portb_read(0);
}

void tmp95c061_device::pb_w(uint8_t data)
{
m_port_latch[0xb] = data;
m_portb_write(0, data, 0xff);
}

void tmp95c061_device::pbcr_w(uint8_t data)
{
m_port_control[0xb] = data;
}

void tmp95c061_device::pbfc_w(uint8_t data)
{
m_port_function[0xb] = data;
}


uint8_t tmp95c061_device::trun_r()
{
return m_trun;
Expand Down
Loading

0 comments on commit 75cbe79

Please sign in to comment.