From caf1e140ba46624eed118124bd1bb9fb45ca57ce Mon Sep 17 00:00:00 2001 From: AJR Date: Fri, 18 Dec 2020 17:38:54 -0500 Subject: [PATCH] dphh8213: Improve inputs; work around unemulated SPI device --- src/mame/drivers/st22xx_bbl338.cpp | 90 +++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/src/mame/drivers/st22xx_bbl338.cpp b/src/mame/drivers/st22xx_bbl338.cpp index 28680e110f7..9c6c1bb5fad 100644 --- a/src/mame/drivers/st22xx_bbl338.cpp +++ b/src/mame/drivers/st22xx_bbl338.cpp @@ -14,21 +14,36 @@ public: , m_maincpu(*this, "maincpu") , m_screen(*this, "screen") , m_lcdc(*this, "lcdc") + , m_input_matrix(*this, "IN%u", 1U) + , m_portb(0xff) { } void st22xx_bbl338(machine_config &config); +protected: + virtual void machine_start() override; + private: + u8 porta_r(); + void portb_w(u8 data); + void st22xx_bbl338_map(address_map &map); required_device m_maincpu; required_device m_screen; required_device m_lcdc; + required_ioport_array<4> m_input_matrix; u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); + + u8 m_portb; }; +void st22xx_bbl338_state::machine_start() +{ + save_item(NAME(m_portb)); +} void st22xx_bbl338_state::st22xx_bbl338_map(address_map &map) { @@ -43,39 +58,71 @@ u32 st22xx_bbl338_state::screen_update(screen_device &screen, bitmap_rgb32 &bitm return m_lcdc->render_to_bitmap(screen, bitmap, cliprect); } +u8 st22xx_bbl338_state::porta_r() +{ + u8 input = 0x3f; + + // irregular port configuration + if (!BIT(m_portb, 0)) + input &= m_input_matrix[0]->read(); + for (int i = 1; i < 4; i++) + if (!BIT(m_portb, i * 2 - 1)) + input &= m_input_matrix[i]->read(); + + // TODO: bit 7 is I/O for some bitbanged SPI device (used for the menu) + input |= 0xc0; + return input; +} + +void st22xx_bbl338_state::portb_w(u8 data) +{ + m_portb = data; +} static INPUT_PORTS_START(st22xx_bbl338) - PORT_START("IN0") // not confirmed, but probably similar to other units - PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_UNUSED) // maybe ON/OFF - PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP) - PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) - PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) - PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) - PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_START1) - PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_BUTTON3) PORT_NAME("SOUND") - PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("B") - - PORT_START("IN1") // not confirmed, but probably similar to other units - PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("A") - PORT_BIT(0x06, IP_ACTIVE_LOW, IPT_UNUSED) - PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_UNUSED) - PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_UNUSED) - PORT_BIT(0xe0, IP_ACTIVE_LOW, IPT_UNUSED) + PORT_START("IN1") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_START1) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x30, IP_ACTIVE_LOW, IPT_UNUSED) PORT_START("IN2") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) + PORT_BIT(0x30, IP_ACTIVE_LOW, IPT_UNUSED) + + PORT_START("IN3") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_UNUSED) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("A") + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_UNUSED) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("B") + PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) + PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP) + + PORT_START("IN4") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x0e, IP_ACTIVE_LOW, IPT_UNUSED) + PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_UNKNOWN) + + PORT_START("PORTC") PORT_CONFNAME( 0x01, 0x01, DEF_STR( Language ) ) PORT_CONFSETTING( 0x00, "Chinese" ) PORT_CONFSETTING( 0x01, "English" ) - PORT_BIT(0xfe, IP_ACTIVE_LOW, IPT_UNUSED) // probably unused + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_UNKNOWN) + PORT_BIT(0xf6, IP_ACTIVE_LOW, IPT_UNUSED) // probably unused INPUT_PORTS_END void st22xx_bbl338_state::st22xx_bbl338(machine_config &config) { - ST2302U(config, m_maincpu, 12000000); // likely higher clock + ST2302U(config, m_maincpu, 24000000); m_maincpu->set_addrmap(AS_DATA, &st22xx_bbl338_state::st22xx_bbl338_map); - m_maincpu->in_pa_callback().set_ioport("IN0"); - m_maincpu->in_pb_callback().set_ioport("IN1"); - m_maincpu->in_pc_callback().set_ioport("IN2"); + m_maincpu->in_pa_callback().set(FUNC(st22xx_bbl338_state::porta_r)); + m_maincpu->out_pb_callback().set(FUNC(st22xx_bbl338_state::portb_w)); + m_maincpu->in_pc_callback().set_ioport("PORTC"); // incorrect for bbl338 SCREEN(config, m_screen, SCREEN_TYPE_LCD); @@ -101,6 +148,7 @@ ROM_END ROM_START( dphh8213 ) ROM_REGION( 0x200000, "maincpu", 0 ) ROM_LOAD( "mx29lv160cb.u1", 0x000000, 0x200000, CRC(c8e7e355) SHA1(726f28c2c9ab012a6842f9f30a0a71538741ba14) ) + ROM_FILL( 0x00009f, 2, 0xea ) // NOP out SPI check ROM_END // this is uses a higher resolution display than the common units, but not as high as the SunPlus based ones