From f1d7874a65e1bb8401c1e4008aecc6ad2777f220 Mon Sep 17 00:00:00 2001 From: 987123879113 <63495610+987123879113@users.noreply.github.com> Date: Tue, 29 Nov 2022 02:16:35 +0900 Subject: konami/hornet.cpp, konami/cobra.cpp, konami/nwk-tr.cpp: Refactored JVS host code. (#10614) * Refactored JVS host code into a common device for Konami PPC400 series systems. * konami/nwk-tr.cpp: Implemented JVS. * konami/cobra.cpp: Replaced JVS code and hooked up Windy2 I/O for bujutsu. --- src/mame/konami/cobra.cpp | 347 ++++--------------------------------- src/mame/konami/hornet.cpp | 122 ++----------- src/mame/konami/konppc_jvshost.cpp | 93 ++++++++++ src/mame/konami/konppc_jvshost.h | 40 +++++ src/mame/konami/nwk-tr.cpp | 52 +++++- 5 files changed, 224 insertions(+), 430 deletions(-) create mode 100644 src/mame/konami/konppc_jvshost.cpp create mode 100644 src/mame/konami/konppc_jvshost.h diff --git a/src/mame/konami/cobra.cpp b/src/mame/konami/cobra.cpp index 390f8091534..99675d67011 100644 --- a/src/mame/konami/cobra.cpp +++ b/src/mame/konami/cobra.cpp @@ -315,18 +315,21 @@ #include "emu.h" + +#include "k001604.h" +#include "konppc_jvshost.h" +#include "windy2.h" + #include "bus/ata/ataintf.h" #include "bus/ata/idehd.h" #include "cpu/powerpc/ppc.h" #include "machine/lpci.h" -#include "machine/jvshost.h" -#include "machine/jvsdev.h" #include "machine/timekpr.h" -#include "k001604.h" +#include "sound/dmadac.h" +#include "sound/rf5c400.h" #include "video/poly.h" #include "video/rgbutil.h" -#include "sound/rf5c400.h" -#include "sound/dmadac.h" + #include "emupal.h" #include "screen.h" #include "speaker.h" @@ -337,7 +340,6 @@ #define S2MFIFO_VERBOSE 0 #define LOG_DEBUG_STATES 0 -#define LOG_JVS 0 #define LOG_GFX_RAM_WRITES 0 #define LOG_DRAW_COMMANDS 0 @@ -495,205 +497,6 @@ private: event_delegate m_event_callback; }; - -/* Cobra JVS Device class */ - -class cobra_jvs : public jvs_device -{ -public: - template - cobra_jvs(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&jvs_host_tag, bool enable) - : cobra_jvs(mconfig, tag, owner, clock) - { - host.set_tag(std::forward(jvs_host_tag)); - set_main_board(enable); - } - - cobra_jvs(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - - //DECLARE_WRITE_LINE_MEMBER(coin_1_w); - //DECLARE_WRITE_LINE_MEMBER(coin_2_w); - void set_main_board(bool enable) { is_main_board = enable; } - void increase_coin_counter(uint8_t which); - -protected: - virtual bool switches(uint8_t *&buf, uint8_t count_players, uint8_t bytes_per_switch) override; - virtual bool coin_counters(uint8_t *&buf, uint8_t count) override; - virtual void function_list(uint8_t *&buf) override; - -private: - bool is_main_board; - int m_coin_counter[2]; - optional_ioport m_test_port; - optional_ioport_array<2> m_player_ports; -}; - -DEFINE_DEVICE_TYPE(COBRA_JVS, cobra_jvs, "cobra_jvs", "JVS (COBRA)") - -cobra_jvs::cobra_jvs(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : jvs_device(mconfig, COBRA_JVS, tag, owner, clock), - m_test_port(*this, ":TEST"), - m_player_ports(*this, {":P1", ":P2"}) -{ - m_coin_counter[0] = 0; - m_coin_counter[1] = 0; -} - -#if 0 -WRITE_LINE_MEMBER(cobra_jvs::coin_1_w) -{ - if(state) - m_coin_counter[0]++; -} - -WRITE_LINE_MEMBER(cobra_jvs::coin_2_w) -{ - if(state) - m_coin_counter[1]++; -} -#endif - -void cobra_jvs::increase_coin_counter(uint8_t which) -{ - m_coin_counter[which]++; -} - -// TODO: this certainly isn't correct, all three JVS points to the same capabilities! -void cobra_jvs::function_list(uint8_t *&buf) -{ - if(this->is_main_board == false) - return; - - // SW input - 2 players, 13 bits - *buf++ = 0x01; - *buf++ = 2; - *buf++ = 13; - *buf++ = 0; - - // Coin input - 2 slots - *buf++ = 0x02; - *buf++ = 2; - *buf++ = 0; - *buf++ = 0; - - // Analog input - 8 channels - *buf++ = 0x03; - *buf++ = 8; - *buf++ = 16; - *buf++ = 0; - - // Driver out - 6 channels - *buf++ = 0x12; - *buf++ = 6; - *buf++ = 0; - *buf++ = 0; -} - -bool cobra_jvs::switches(uint8_t *&buf, uint8_t count_players, uint8_t bytes_per_switch) -{ -#if LOG_JVS - printf("jvs switch read: num players %d, bytes %d\n", count_players, bytes_per_switch); -#endif - - if(this->is_main_board == false) - return false; - - if (count_players > 2 || bytes_per_switch > 2) - return false; - - *buf++ = m_test_port.read_safe(0); - - for (int i=0; i < count_players; i++) - { - uint32_t pval = m_player_ports[i].read_safe(0); - for (int j=0; j < bytes_per_switch; j++) - { - *buf++ = (uint8_t)(pval >> ((1-j) * 8)); - } - } - return true; -} - -bool cobra_jvs::coin_counters(uint8_t *&buf, uint8_t count) -{ -#if LOG_JVS - printf("jvs coin counter read: count %d\n", count); -#endif - - if(this->is_main_board == false) - return false; - - //printf("recv %04x\n",m_coin_counter[0]); - - if (count > 2) - return false; - - *buf++ = m_coin_counter[0] >> 8; *buf++ = m_coin_counter[0]; - - if(count > 1) - { - *buf++ = m_coin_counter[1] >> 8; *buf++ = m_coin_counter[1]; - } - - return true; -} - - -class cobra_jvs_host : public jvs_host -{ -public: - cobra_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - void write(uint8_t, const uint8_t *&rec_data, uint32_t &rec_size); - -private: - uint8_t m_send[512]; - int m_send_ptr; -}; - -DEFINE_DEVICE_TYPE(COBRA_JVS_HOST, cobra_jvs_host, "cobra_jvs_host", "JVS-HOST (COBRA)") - -cobra_jvs_host::cobra_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : jvs_host(mconfig, COBRA_JVS_HOST, tag, owner, clock) -{ - m_send_ptr = 0; -} - -void cobra_jvs_host::write(uint8_t data, const uint8_t *&rec_data, uint32_t &rec_size) -{ - m_send[m_send_ptr++] = data; - push(data); - - if (m_send[0] == 0xe0) - { - if (m_send_ptr > 2) - { - uint8_t length = m_send[2]; - if (length == 0xff) - length = 4; - else - length = length + 3; - - if (m_send_ptr >= length) - { - commit_encoded(); - - get_encoded_reply(rec_data, rec_size); - - m_send_ptr = 0; - return; - } - } - } - else - { - m_send_ptr = 0; - } - - rec_data = nullptr; - rec_size = 0; -} - - /* Cobra driver class */ class cobra_state : public driver_device @@ -706,14 +509,11 @@ public: m_gfxcpu(*this, "gfxcpu"), m_gfx_pagetable(*this, "pagetable"), m_k001604(*this, "k001604"), - m_jvs1(*this, "cobra_jvs1"), - m_jvs2(*this, "cobra_jvs2"), - m_jvs3(*this, "cobra_jvs3"), m_ata(*this, "ata"), m_screen(*this, "screen"), m_palette(*this, "palette"), m_legacy_pci(*this, "pcibus"), - m_jvs_host(*this, "cobra_jvs_host"), + m_jvs_host(*this, "jvs_host"), m_dmadac(*this, "dac%u", 1U), m_generic_paletteram_32(*this, "paletteram"), m_main_ram(*this, "main_ram"), @@ -728,14 +528,11 @@ public: required_device m_gfxcpu; required_shared_ptr m_gfx_pagetable; required_device m_k001604; - required_device m_jvs1; - required_device m_jvs2; - required_device m_jvs3; required_device m_ata; required_device m_screen; required_device m_palette; required_device m_legacy_pci; - required_device m_jvs_host; + required_device m_jvs_host; required_device_array m_dmadac; required_shared_ptr m_generic_paletteram_32; required_shared_ptr m_main_ram; @@ -751,7 +548,7 @@ public: uint32_t sub_comram_r(offs_t offset); void sub_comram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t sub_unk7e_r(); + uint8_t sub_unk7e_r(offs_t offset); void sub_debug_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); uint32_t sub_unk1_r(offs_t offset, uint32_t mem_mask = ~0); void sub_unk1_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); @@ -842,7 +639,6 @@ public: void init_racjamdx(); void init_bujutsu(); void init_cobra(); - DECLARE_INPUT_CHANGED_MEMBER(coin_inserted); virtual void machine_start() override; virtual void machine_reset() override; virtual void video_start() override; @@ -851,6 +647,7 @@ public: void cobra_video_exit(); int decode_debug_state_value(int v); void cobra(machine_config &config); + void bujutsu(machine_config &config); void cobra_gfx_map(address_map &map); void cobra_main_map(address_map &map); void cobra_sub_map(address_map &map); @@ -1465,11 +1262,12 @@ uint64_t cobra_state::main_fifo_r(offs_t offset, uint64_t mem_mask) // // 7 6 5 4 3 2 1 0 //---------------- + // x Unknown, must be 0 for coins to be updated // x S2M FIFO interrupt active // x Graphics board/FIFO busy flag // x M2S FIFO interrupt active - int value = 0x01; + int value = 0; value |= (m_main_int_active & MAIN_INT_S2M) ? 0x00 : 0x02; value |= (m_main_int_active & MAIN_INT_M2S) ? 0x00 : 0x08; @@ -1848,9 +1646,16 @@ void cobra_state::sub_mainbd_w(offs_t offset, uint32_t data, uint32_t mem_mask) } } -uint32_t cobra_state::sub_unk7e_r() +uint8_t cobra_state::sub_unk7e_r(offs_t offset) { - return 0xffffffff; + uint8_t r = 0; + + if (offset == 3) + { + r |= !m_jvs_host->sense(); + } + + return ~r; } void cobra_state::sub_debug_w(offs_t offset, uint32_t data, uint32_t mem_mask) @@ -1969,31 +1774,9 @@ void cobra_state::sub_sound_dma_w(offs_t offset, uint32_t data) void cobra_state::sub_jvs_w(uint8_t data) { -#if LOG_JVS - printf("sub_jvs_w: %02X\n", data); -#endif - - const uint8_t *rec_data; - uint32_t rec_size; - - m_jvs_host->write(data, rec_data, rec_size); - - if (rec_size > 0) - { -#if LOG_JVS - printf("jvs reply "); - for (int i=0; i < rec_size; i++) - { - printf("%02X ", rec_data[i]); - } - printf("\n"); -#endif - - for (int i=0; i < rec_size; i++) - { - m_subcpu->ppc4xx_spu_receive_byte(rec_data[i]); - } - } + bool accepted = m_jvs_host->write(data); + if (accepted) + m_jvs_host->read(); } void cobra_state::cobra_sub_map(address_map &map) @@ -3113,68 +2896,7 @@ void cobra_state::cobra_gfx_map(address_map &map) /*****************************************************************************/ - -INPUT_CHANGED_MEMBER(cobra_state::coin_inserted) -{ - if(newval) - { - uint8_t coin_chute = (uint8_t)param & 1; - m_jvs1->increase_coin_counter(coin_chute); - m_jvs2->increase_coin_counter(coin_chute); - m_jvs3->increase_coin_counter(coin_chute); - } -} - INPUT_PORTS_START( cobra ) - PORT_START("TEST") - PORT_SERVICE_NO_TOGGLE( 0x80, IP_ACTIVE_HIGH) /* Test Button */ - PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN ) - PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN ) - PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN ) - PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) - - PORT_START("P1") - PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_START1 ) - PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_SERVICE1 ) - PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) - PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) - PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) - PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) - PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Punch") - PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Kick") - PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Guard") - PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_UNUSED ) - - PORT_START("P2") - PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_START2 ) - PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_SERVICE2 ) - PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) - PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) - PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) - PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) - PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Punch") - PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Kick") - PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Guard") - PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_UNUSED ) - PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_UNUSED ) - - PORT_START("COINS") - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_COIN1) PORT_CHANGED_MEMBER(DEVICE_SELF, cobra_state,coin_inserted, 0)//PORT_WRITE_LINE_DEVICE_MEMBER("cobra_jvs1", cobra_jvs, coin_1_w) - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_COIN2) PORT_CHANGED_MEMBER(DEVICE_SELF, cobra_state,coin_inserted, 1) //PORT_WRITE_LINE_DEVICE_MEMBER("cobra_jvs1", cobra_jvs, coin_2_w) INPUT_PORTS_END WRITE_LINE_MEMBER(cobra_state::ide_interrupt) @@ -3240,6 +2962,7 @@ void cobra_state::cobra(machine_config &config) m_maincpu->set_vblank_int("screen", FUNC(cobra_state::cobra_vblank)); PPC403GA(config, m_subcpu, 32000000); /* 403GA, 33? MHz */ + m_subcpu->set_serial_clock(XTAL(7'372'800)); // set serial clock to 7.3728MHz to allow for JVS comm at 115200 baud m_subcpu->set_addrmap(AS_PROGRAM, &cobra_state::cobra_sub_map); PPC604(config, m_gfxcpu, 100000000); /* 604, 100? MHz */ @@ -3280,10 +3003,14 @@ void cobra_state::cobra(machine_config &config) K001604(config, m_k001604, 0); // on the LAN board in Racing Jam DX m_k001604->set_palette(m_palette); - COBRA_JVS_HOST(config, m_jvs_host, 4000000); - COBRA_JVS(config, m_jvs1, 0, m_jvs_host, true); - COBRA_JVS(config, m_jvs2, 0, m_jvs_host, true); - COBRA_JVS(config, m_jvs3, 0, m_jvs_host, true); + KONPPC_JVS_HOST(config, m_jvs_host, 4000000); + m_jvs_host->output_callback().set([this](uint8_t c) { m_subcpu->ppc4xx_spu_receive_byte(c); }); +} + +void cobra_state::bujutsu(machine_config &config) +{ + cobra(config); + KONAMI_WINDY2_JVS_IO_2L12B_PANEL(config, "windy2_jvsio", 0, m_jvs_host); } void cobra_state::rf5c400_map(address_map& map) @@ -3557,5 +3284,5 @@ ROM_END /*************************************************************************/ -GAME( 1997, bujutsu, 0, cobra, cobra, cobra_state, init_bujutsu, ROT0, "Konami", "Fighting Wu-Shu 2nd! (ver JAA)", MACHINE_NOT_WORKING | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_TIMING ) -GAME( 1997, racjamdx, 0, cobra, cobra, cobra_state, init_racjamdx, ROT0, "Konami", "Racing Jam DX", MACHINE_NOT_WORKING | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_TIMING | MACHINE_NODEVICE_LAN ) +GAME( 1997, bujutsu, 0, bujutsu, cobra, cobra_state, init_bujutsu, ROT0, "Konami", "Fighting Wu-Shu 2nd! (ver JAA)", MACHINE_NOT_WORKING | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_TIMING ) +GAME( 1997, racjamdx, 0, cobra, cobra, cobra_state, init_racjamdx, ROT0, "Konami", "Racing Jam DX", MACHINE_NOT_WORKING | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_TIMING | MACHINE_NODEVICE_LAN ) diff --git a/src/mame/konami/hornet.cpp b/src/mame/konami/hornet.cpp index 4a8f667c4fa..74e28975838 100644 --- a/src/mame/konami/hornet.cpp +++ b/src/mame/konami/hornet.cpp @@ -353,6 +353,7 @@ Jumpers set on GFX PCB to scope monitor: #include "k037122.h" #include "konami_gn676_lan.h" #include "konppc.h" +#include "konppc_jvshost.h" #include "windy2.h" #include "cpu/m68000/m68000.h" @@ -361,8 +362,6 @@ Jumpers set on GFX PCB to scope monitor: #include "machine/adc1213x.h" #include "machine/ds2401.h" #include "machine/eepromser.h" -#include "machine/jvsdev.h" -#include "machine/jvshost.h" #include "machine/k033906.h" #include "machine/timekpr.h" #include "machine/watchdog.h" @@ -377,65 +376,6 @@ Jumpers set on GFX PCB to scope monitor: #include "layout/generic.h" - -DECLARE_DEVICE_TYPE(HORNET_JVS_HOST, hornet_jvs_host) - -class hornet_jvs_host : public jvs_host -{ -public: - // construction/destruction - hornet_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - void read(); - void write(uint8_t *data, int length); - - DECLARE_READ_LINE_MEMBER( sense ); - - auto output_callback() { return output_cb.bind(); } - -protected: - virtual void device_start() override; - -private: - devcb_write8 output_cb; -}; - -DEFINE_DEVICE_TYPE(HORNET_JVS_HOST, hornet_jvs_host, "hornet_jvs_host", "JVS Host (Hornet)") - -hornet_jvs_host::hornet_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : jvs_host(mconfig, HORNET_JVS_HOST, tag, owner, clock), - output_cb(*this) -{ -} - -void hornet_jvs_host::device_start() -{ - jvs_host::device_start(); - output_cb.resolve_safe(); -} - -READ_LINE_MEMBER( hornet_jvs_host::sense ) -{ - return !get_address_set_line(); -} - -void hornet_jvs_host::read() -{ - const uint8_t *data; - uint32_t length; - - get_encoded_reply(data, length); - - for (int i = 0; i < length; i++) - output_cb(data[i]); -} - -void hornet_jvs_host::write(uint8_t *data, int length) -{ - for (int i = 0; i < length; i++) - push(data[i]); - commit_raw(); -} - namespace { class hornet_state : public driver_device @@ -465,7 +405,7 @@ public: m_comm_bank(*this, "comm_bank"), m_lan_ds2401(*this, "lan_serial_id"), m_watchdog(*this, "watchdog"), - m_hornet_jvs_host(*this, "hornet_jvs_host"), + m_jvs_host(*this, "jvs_host"), m_cg_view(*this, "cg_view"), m_k033906(*this, "k033906_%u", 1U) { } @@ -492,7 +432,6 @@ protected: private: // TODO: Needs verification on real hardware static const int m_sound_timer_usec = 2800; - static constexpr int JVS_BUFFER_SIZE = 1024; required_shared_ptr m_workram; optional_shared_ptr_array m_sharc_dataram; @@ -516,14 +455,11 @@ private: optional_memory_bank m_comm_bank; optional_device m_lan_ds2401; required_device m_watchdog; - required_device m_hornet_jvs_host; + required_device m_jvs_host; memory_view m_cg_view; optional_device_array m_k033906; emu_timer *m_sound_irq_timer; - std::unique_ptr m_jvs_sdata; - uint32_t m_jvs_sdata_ptr; - bool m_jvs_is_escape_byte; uint16_t m_gn680_latch; uint16_t m_gn680_ret0; @@ -601,7 +537,7 @@ uint8_t hornet_state::sysreg_r(offs_t offset) 0x01 = ADDO (ADC DO) */ r = 0x70; - r |= m_hornet_jvs_host->sense() << 7; + r |= m_jvs_host->sense() << 7; if (m_x76f041) r |= m_x76f041->read_sda() << 3; r |= m_adc12138->do_r() | (m_adc12138->eoc_r() << 2); @@ -1151,20 +1087,12 @@ void hornet_state::machine_start() { m_pcb_digit.resolve(); - m_jvs_sdata_ptr = 0; - m_jvs_sdata = make_unique_clear(JVS_BUFFER_SIZE); - m_jvs_is_escape_byte = false; - // set conservative DRC options m_maincpu->ppcdrc_set_options(PPCDRC_COMPATIBLE_OPTIONS); // configure fast RAM regions for DRC m_maincpu->ppcdrc_add_fastram(0x00000000, 0x003fffff, false, m_workram); - save_pointer(NAME(m_jvs_sdata), JVS_BUFFER_SIZE); - save_item(NAME(m_jvs_sdata_ptr)); - save_item(NAME(m_jvs_is_escape_byte)); - m_sound_irq_timer = timer_alloc(FUNC(hornet_state::sound_irq), this); } @@ -1186,9 +1114,6 @@ void hornet_state::machine_reset() if (membank("slave_cgboard_bank")) membank("slave_cgboard_bank")->set_base(memregion("master_cgboard")->base()); } - - m_jvs_sdata_ptr = 0; - m_jvs_is_escape_byte = false; } double hornet_state::adc12138_input_callback(uint8_t input) @@ -1270,8 +1195,8 @@ void hornet_state::hornet(machine_config &config) m_konppc->set_num_boards(1); m_konppc->set_cbboard_type(konppc_device::CGBOARD_TYPE_HORNET); - HORNET_JVS_HOST(config, m_hornet_jvs_host, 0); - m_hornet_jvs_host->output_callback().set([this](uint8_t c) { m_maincpu->ppc4xx_spu_receive_byte(c); }); + KONPPC_JVS_HOST(config, m_jvs_host, 0); + m_jvs_host->output_callback().set([this](uint8_t c) { m_maincpu->ppc4xx_spu_receive_byte(c); }); } void hornet_state::hornet_x76(machine_config &config) @@ -1297,7 +1222,7 @@ void hornet_state::nbapbp(machine_config &config) // with the 2L6B panel dipswitch settings on the Windy2 board. // NOTE: Harness JVS + cabinet 4 player will work with a second JVS I/O device hooked up, but then // the official recommended setting of cabinet type 4 player + harness JAMMA breaks. - KONAMI_WINDY2_JVS_IO_2L6B_PANEL(config, "windy2_jvsio", 0, m_hornet_jvs_host); + KONAMI_WINDY2_JVS_IO_2L6B_PANEL(config, "windy2_jvsio", 0, m_jvs_host); } void hornet_state::terabrst(machine_config &config) //todo: add K056800 from I/O board @@ -1410,36 +1335,9 @@ void hornet_state::sscope2_voodoo1(machine_config& config) void hornet_state::jamma_jvs_w(uint8_t data) { - bool is_escape_byte = m_jvs_is_escape_byte; - m_jvs_is_escape_byte = false; - - // Throw away the buffer and wait for the next sync marker instead of overflowing when - // a invalid packet is filling the entire buffer. - if (m_jvs_sdata_ptr >= JVS_BUFFER_SIZE) - m_jvs_sdata_ptr = 0; - - if (m_jvs_sdata_ptr == 0 && data != 0xe0) - return; - - if (m_jvs_sdata_ptr > 0 && data == 0xd0) - { - m_jvs_is_escape_byte = true; - return; - } - - m_jvs_sdata[m_jvs_sdata_ptr++] = is_escape_byte ? data + 1 : data; - - const bool is_complete_packet = m_jvs_sdata_ptr >= 5 - && m_jvs_sdata_ptr == m_jvs_sdata[2] + 3 - && m_jvs_sdata[0] == 0xe0 - && m_jvs_sdata[1] != 0x00 - && m_jvs_sdata[m_jvs_sdata_ptr - 1] == (std::accumulate(&m_jvs_sdata[1], &m_jvs_sdata[m_jvs_sdata_ptr - 1], 0) & 0xff); - if (is_complete_packet) - { - m_hornet_jvs_host->write(&m_jvs_sdata[1], m_jvs_sdata_ptr - 2); - m_hornet_jvs_host->read(); - m_jvs_sdata_ptr = 0; - } + bool accepted = m_jvs_host->write(data); + if (accepted) + m_jvs_host->read(); } /*****************************************************************************/ diff --git a/src/mame/konami/konppc_jvshost.cpp b/src/mame/konami/konppc_jvshost.cpp new file mode 100644 index 00000000000..db52d311014 --- /dev/null +++ b/src/mame/konami/konppc_jvshost.cpp @@ -0,0 +1,93 @@ +// license:BSD-3-Clause +// copyright-holders:windyfairy +// +// JVS Host implementation shared between multiple PowerPC-based Konami platforms +// + +#include "emu.h" + +#include "konppc_jvshost.h" + +DEFINE_DEVICE_TYPE(KONPPC_JVS_HOST, konppc_jvs_host_device, "konppc_jvs_host", "Konami JVS Host (PowerPC Common)") + +konppc_jvs_host_device::konppc_jvs_host_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : jvs_host(mconfig, KONPPC_JVS_HOST, tag, owner, clock), + output_cb(*this) +{ +} + +void konppc_jvs_host_device::device_start() +{ + jvs_host::device_start(); + + output_cb.resolve_safe(); + + m_jvs_sdata = make_unique_clear(JVS_BUFFER_SIZE); + m_jvs_is_escape_byte = false; + m_jvs_sdata_ptr = 0; + + save_pointer(NAME(m_jvs_sdata), JVS_BUFFER_SIZE); + save_item(NAME(m_jvs_sdata_ptr)); + save_item(NAME(m_jvs_is_escape_byte)); +} + +void konppc_jvs_host_device::device_reset() +{ + jvs_host::device_reset(); + + m_jvs_is_escape_byte = false; + m_jvs_sdata_ptr = 0; +} + +READ_LINE_MEMBER( konppc_jvs_host_device::sense ) +{ + return !get_address_set_line(); +} + +void konppc_jvs_host_device::read() +{ + const uint8_t *data; + uint32_t length; + + get_encoded_reply(data, length); + + for (int i = 0; i < length; i++) + output_cb(data[i]); +} + +bool konppc_jvs_host_device::write(uint8_t data) +{ + bool is_escape_byte = m_jvs_is_escape_byte; + m_jvs_is_escape_byte = false; + + // Throw away the buffer and wait for the next sync marker instead of overflowing when + // a invalid packet is filling the entire buffer. + if (m_jvs_sdata_ptr >= JVS_BUFFER_SIZE) + m_jvs_sdata_ptr = 0; + + if (m_jvs_sdata_ptr == 0 && data != 0xe0) + return false; + + if (m_jvs_sdata_ptr > 0 && data == 0xd0) + { + m_jvs_is_escape_byte = true; + return false; + } + + m_jvs_sdata[m_jvs_sdata_ptr++] = is_escape_byte ? data + 1 : data; + + const bool is_complete_packet = m_jvs_sdata_ptr >= 5 + && m_jvs_sdata_ptr == m_jvs_sdata[2] + 3 + && m_jvs_sdata[0] == 0xe0 + && m_jvs_sdata[1] != 0x00 + && m_jvs_sdata[m_jvs_sdata_ptr - 1] == (std::accumulate(&m_jvs_sdata[1], &m_jvs_sdata[m_jvs_sdata_ptr - 1], 0) & 0xff); + if (is_complete_packet) + { + for (int i = 1; i < m_jvs_sdata_ptr - 1; i++) + push(m_jvs_sdata[i]); + commit_raw(); + m_jvs_sdata_ptr = 0; + } + + return is_complete_packet; +} diff --git a/src/mame/konami/konppc_jvshost.h b/src/mame/konami/konppc_jvshost.h new file mode 100644 index 00000000000..d09977b0fd8 --- /dev/null +++ b/src/mame/konami/konppc_jvshost.h @@ -0,0 +1,40 @@ +// license:BSD-3-Clause +// copyright-holders:windyfairy +#ifndef MAME_KONAMI_KONPPC_JVSHOST_H +#define MAME_KONAMI_KONPPC_JVSHOST_H + +#pragma once + +#include "machine/jvshost.h" + +class konppc_jvs_host_device : public jvs_host +{ +public: + // construction/destruction + konppc_jvs_host_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + // configuration + auto output_callback() { return output_cb.bind(); } + + void read(); + bool write(uint8_t data); + + DECLARE_READ_LINE_MEMBER( sense ); + +protected: + virtual void device_start() override; + virtual void device_reset() override; + +private: + static constexpr int JVS_BUFFER_SIZE = 1024; + + devcb_write8 output_cb; + + std::unique_ptr m_jvs_sdata; + uint32_t m_jvs_sdata_ptr; + bool m_jvs_is_escape_byte; +}; + +DECLARE_DEVICE_TYPE(KONPPC_JVS_HOST, konppc_jvs_host_device) + +#endif // MAME_KONAMI_KONPPC_JVSHOST_H diff --git a/src/mame/konami/nwk-tr.cpp b/src/mame/konami/nwk-tr.cpp index a23cfd4da9f..ae40c718306 100644 --- a/src/mame/konami/nwk-tr.cpp +++ b/src/mame/konami/nwk-tr.cpp @@ -268,24 +268,28 @@ Thrill Drive 713A13 - 713A14 - */ #include "emu.h" + +#include "k001604.h" +#include "k573mcal.h" +#include "konami_gn676_lan.h" +#include "konppc.h" +#include "konppc_jvshost.h" + #include "cpu/m68000/m68000.h" #include "cpu/powerpc/ppc.h" #include "cpu/sharc/sharc.h" #include "machine/adc1213x.h" #include "machine/k033906.h" -#include "konami_gn676_lan.h" -#include "konppc.h" #include "machine/timekpr.h" -//#include "machine/x76f041.h" +#include "machine/x76f041.h" #include "sound/k056800.h" #include "sound/rf5c400.h" -#include "k001604.h" #include "video/voodoo.h" + #include "emupal.h" #include "screen.h" #include "speaker.h" - namespace { class nwktr_state : public driver_device @@ -309,12 +313,14 @@ public: m_palette(*this, "palette"), m_generic_paletteram_32(*this, "paletteram"), m_sharc_dataram(*this, "sharc%u_dataram", 0U), - m_cg_view(*this, "cg_view") + m_cg_view(*this, "cg_view"), + m_jvs_host(*this, "jvs_host") { } void thrilld(machine_config &config); void nwktr(machine_config &config); + void init_nwktr(); void init_racingj(); void init_thrilld(); @@ -325,9 +331,10 @@ protected: private: // TODO: Needs verification on real hardware static const int m_sound_timer_usec = 2400; + static constexpr int JVS_BUFFER_SIZE = 1024; required_shared_ptr m_work_ram; - required_device m_maincpu; + required_device m_maincpu; required_device m_audiocpu; required_device_array m_dsp; required_device m_k056800; @@ -343,6 +350,7 @@ private: required_shared_ptr m_generic_paletteram_32; optional_shared_ptr_array m_sharc_dataram; memory_view m_cg_view; + required_device m_jvs_host; emu_timer *m_sound_irq_timer; bool m_exrgb; @@ -353,6 +361,7 @@ private: void soundtimer_en_w(uint16_t data); void soundtimer_count_w(uint16_t data); double adc12138_input_callback(uint8_t input); + void jamma_jvs_w(uint8_t data); TIMER_CALLBACK_MEMBER(sound_irq); @@ -402,7 +411,8 @@ uint8_t nwktr_state::sysreg_r(offs_t offset) r = m_in[2]->read(); break; case 3: - r = m_adc12138->do_r() | (m_adc12138->eoc_r() << 2); + r |= m_jvs_host->sense() << 7; + r |= m_adc12138->do_r() | (m_adc12138->eoc_r() << 2); break; case 4: r = m_dsw->read(); @@ -423,6 +433,13 @@ void nwktr_state::sysreg_w(offs_t offset, uint8_t data) m_pcb_digit[offset] = bitswap<7>(~data , 0, 1, 2, 3, 4, 5, 6); break; + case 3: + /* + The bit used for JVSTXEN changes between 3 and 4 based on the lower 2 bits of IN2. + If m_in[2]->read() & 3 != 0, bit 4 is used. Otherwise, bit 3 is used. + */ + break; + case 4: { int cs = (data >> 3) & 0x1; @@ -735,6 +752,9 @@ void nwktr_state::nwktr(machine_config &config) m_konppc->set_cbboard_type(konppc_device::CGBOARD_TYPE_NWKTR); KONAMI_GN676_LAN(config, "gn676_lan", 0, m_work_ram); + + KONPPC_JVS_HOST(config, m_jvs_host, 0); + m_jvs_host->output_callback().set([this](uint8_t c) { m_maincpu->ppc4xx_spu_receive_byte(c); }); } void nwktr_state::thrilld(machine_config &config) @@ -744,14 +764,30 @@ void nwktr_state::thrilld(machine_config &config) /*****************************************************************************/ +void nwktr_state::jamma_jvs_w(uint8_t data) +{ + bool accepted = m_jvs_host->write(data); + if (accepted) + m_jvs_host->read(); +} + +/*****************************************************************************/ + +void nwktr_state::init_nwktr() +{ + m_maincpu->ppc4xx_spu_set_tx_handler(write8smo_delegate(*this, FUNC(nwktr_state::jamma_jvs_w))); +} + void nwktr_state::init_racingj() { + init_nwktr(); m_konppc->set_cgboard_texture_bank(0, "master_cgboard_bank", memregion("master_cgboard")->base()); m_konppc->set_cgboard_texture_bank(0, "slave_cgboard_bank", memregion("slave_cgboard")->base()); // for some reason, additional CG roms are located on the slave CG board... } void nwktr_state::init_thrilld() { + init_nwktr(); m_konppc->set_cgboard_texture_bank(0, "master_cgboard_bank", memregion("master_cgboard")->base()); m_konppc->set_cgboard_texture_bank(0, "slave_cgboard_bank", memregion("master_cgboard")->base()); // ...while this is not the case for thrilld } -- cgit v1.2.3