From 2bc32a86b6cbbb0d3a60698ed09af2eba3d10ac4 Mon Sep 17 00:00:00 2001 From: AJR Date: Thu, 22 Dec 2022 14:48:45 -0500 Subject: nec/pc6001.cpp: Fix joystick multiplexing; add port outputs and HSYNC and VSYNC readback --- src/mame/nec/pc6001.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++------ src/mame/nec/pc6001.h | 9 +++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/mame/nec/pc6001.cpp b/src/mame/nec/pc6001.cpp index a73365e3973..3c948332900 100644 --- a/src/mame/nec/pc6001.cpp +++ b/src/mame/nec/pc6001.cpp @@ -257,6 +257,42 @@ void pc6001_state::nec_ppi8255_w(offs_t offset, uint8_t data) m_ppi->write(offset,data); } +uint8_t pc6001_state::joystick_r() +{ + uint8_t data = m_joymux->output_r(); + + // FIXME: bits 6 and 7 are supposed to be nHSYNC and nVSYNC + if (m_screen->hblank()) + data &= 0xbf; + else + data |= 0x40; + if (m_screen->vblank()) + data &= 0x7f; + else + data |= 0x80; + + return data; +} + +uint8_t pc6001_state::joystick_out_r() +{ + return m_joystick_out; +} + +void pc6001_state::joystick_out_w(uint8_t data) +{ + // bit 7 is output enable for first part of 74LS367 buffer + m_joy[1]->pin_6_w(BIT(data, 7) ? 1 : BIT(data, 0)); + m_joy[1]->pin_7_w(BIT(data, 7) ? 1 : BIT(data, 1)); + m_joy[0]->pin_6_w(BIT(data, 7) ? 1 : BIT(data, 2)); + m_joy[0]->pin_7_w(BIT(data, 7) ? 1 : BIT(data, 3)); + m_joy[1]->pin_8_w(BIT(data, 4)); + m_joy[0]->pin_8_w(BIT(data, 5)); + m_joymux->select_w(BIT(data, 6)); + + m_joystick_out = data; +} + void pc6001_state::pc6001_map(address_map &map) { map.unmap_value_high(); @@ -1383,7 +1419,7 @@ uint8_t pc6001_state::check_keyboard_press() uint8_t pc6001_state::check_joy_press() { // TODO: this may really just rearrange keyboard key presses in a joystick like fashion, somehow akin to Sharp X1 mode - uint8_t p1_key = m_joy[0]->read() ^ 0xff; + uint8_t p1_key = m_joymux->output_r() ^ 0xff; uint8_t shift_key = m_io_key_modifiers->read() & 0x02; uint8_t space_key = m_io_keys[1]->read() & 0x01; uint8_t joy_press; @@ -1694,10 +1730,13 @@ void pc6001_state::pc6001(machine_config &config) /* uart */ I8251(config, "uart", 0); - // TODO: these are unchecked MSX_GENERAL_PURPOSE_PORT(config, m_joy[0], msx_general_purpose_port_devices, "joystick"); MSX_GENERAL_PURPOSE_PORT(config, m_joy[1], msx_general_purpose_port_devices, "joystick"); + LS157_X2(config, m_joymux); + m_joymux->a_in_callback().set(m_joy[1], FUNC(msx_general_purpose_port_device::read)); + m_joymux->b_in_callback().set(m_joy[0], FUNC(msx_general_purpose_port_device::read)); + GENERIC_CARTSLOT(config, m_cart, generic_plain_slot, "pc6001_cart"); SOFTWARE_LIST(config, "cart_list_pc6001").set_original("pc6001_cart"); @@ -1709,8 +1748,9 @@ void pc6001_state::pc6001(machine_config &config) SPEAKER(config, "mono").front_center(); AY8910(config, m_ay, PC6001_MAIN_CLOCK/4); - m_ay->port_a_read_callback().set(m_joy[0], FUNC(msx_general_purpose_port_device::read)); - m_ay->port_b_read_callback().set(m_joy[1], FUNC(msx_general_purpose_port_device::read)); + m_ay->port_a_read_callback().set(FUNC(pc6001_state::joystick_r)); + m_ay->port_b_read_callback().set(FUNC(pc6001_state::joystick_out_r)); + m_ay->port_b_write_callback().set(FUNC(pc6001_state::joystick_out_w)); m_ay->add_route(ALL_OUTPUTS, "mono", 1.00); // TODO: accurate timing on this @@ -1804,8 +1844,9 @@ void pc6001mk2sr_state::pc6001mk2sr(machine_config &config) config.device_remove("aysnd"); YM2203(config, m_ym, PC6001_MAIN_CLOCK/4); - m_ym->port_a_read_callback().set(m_joy[0], FUNC(msx_general_purpose_port_device::read)); - m_ym->port_b_read_callback().set(m_joy[1], FUNC(msx_general_purpose_port_device::read)); + m_ym->port_a_read_callback().set(FUNC(pc6001mk2sr_state::joystick_r)); + m_ym->port_b_read_callback().set(FUNC(pc6001mk2sr_state::joystick_out_r)); + m_ym->port_b_write_callback().set(FUNC(pc6001mk2sr_state::joystick_out_w)); m_ym->add_route(ALL_OUTPUTS, "mono", 1.00); // TODO: 1D 3'5" floppy drive diff --git a/src/mame/nec/pc6001.h b/src/mame/nec/pc6001.h index a1519b7a307..41b5ccfba91 100644 --- a/src/mame/nec/pc6001.h +++ b/src/mame/nec/pc6001.h @@ -10,6 +10,7 @@ #include "cpu/z80/z80.h" #include "imagedev/cassette.h" #include "imagedev/floppy.h" +#include "machine/74157.h" #include "machine/bankdev.h" #include "machine/i8251.h" #include "machine/i8255.h" @@ -43,6 +44,7 @@ public: , m_maincpu(*this, "maincpu") , m_screen(*this, "screen") , m_joy(*this, "joy%u", 1U) + , m_joymux(*this, "joymux") , m_cassette(*this, "cassette") , m_cas_hack(*this, "cas_hack") , m_cart(*this, "cartslot") @@ -78,6 +80,10 @@ public: void ppi_portc_w(uint8_t data); uint8_t ppi_portc_r(); + uint8_t joystick_r(); + uint8_t joystick_out_r(); + void joystick_out_w(uint8_t data); + void pc6001(machine_config &config); protected: required_device m_ppi; @@ -85,6 +91,7 @@ protected: required_device m_maincpu; required_device m_screen; required_device_array m_joy; + required_device m_joymux; optional_device m_cassette; optional_device m_cas_hack; required_device m_cart; @@ -150,6 +157,8 @@ private: uint32_t m_old_key3 = 0; u8 m_old_key_fn; + uint8_t m_joystick_out = 0xff; + emu_timer *m_sub_trig_timer = nullptr; // IRQ model -- cgit v1.2.3