From dbaf7b376d4860def2c87b95a8d2ea319b23b589 Mon Sep 17 00:00:00 2001 From: hap Date: Wed, 1 Feb 2023 23:31:48 +0100 Subject: cothello: add coin handling and sound --- src/devices/sound/beep.cpp | 2 +- src/mame/dataeast/astrof.cpp | 3 +- src/mame/nintendo/cothello.cpp | 133 +++++++++++++++++++++++++++++++++++------ 3 files changed, 117 insertions(+), 21 deletions(-) diff --git a/src/devices/sound/beep.cpp b/src/devices/sound/beep.cpp index 47f4701a662..93a02243878 100644 --- a/src/devices/sound/beep.cpp +++ b/src/devices/sound/beep.cpp @@ -65,7 +65,7 @@ void beep_device::sound_stream_update(sound_stream &stream, std::vector m_maincpu; required_device m_screen; required_shared_ptr m_vram; - required_ioport_array<3> m_inputs; + required_device m_beeper; + required_ioport_array<4> m_inputs; + output_finder<4> m_digits; void main_map(address_map &map); u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - u8 input_r(); u8 coin_r(); + u8 input_r(); void sound_w(u8 data); + + TIMER_CALLBACK_MEMBER(counter_tick); + TIMER_CALLBACK_MEMBER(beeper_off) { m_beeper->set_state(0); } + + u16 m_counter = 0; + emu_timer *m_counter_timer; + emu_timer *m_beeper_off; }; +void cothello_state::machine_start() +{ + m_digits.resolve(); + + m_counter_timer = timer_alloc(FUNC(cothello_state::counter_tick), this); + m_beeper_off = timer_alloc(FUNC(cothello_state::beeper_off), this); + + save_item(NAME(m_counter)); +} + /******************************************************************************* @@ -96,6 +127,46 @@ u32 cothello_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, c I/O *******************************************************************************/ +INPUT_CHANGED_MEMBER(cothello_state::insert_coin) +{ + if (!newval || m_counter_timer->enabled()) + return; + + // reset counter + m_counter = ~0; + m_counter_timer->adjust(attotime::zero); +} + +TIMER_CALLBACK_MEMBER(cothello_state::counter_tick) +{ + m_counter++; + + // highest digit is compared to a digit wheel setting + u8 max = std::clamp(int(m_inputs[3]->read()), 1, 9); + u8 high = (m_counter / 100) % 10; + + if (high == 0 || high == max) + m_maincpu->set_input_line(0, HOLD_LINE); + + if (high != max) + m_counter_timer->adjust(attotime::from_seconds(1)); + + // output counter to 7segs + static const u8 led_map[] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f }; + + m_digits[0] = led_map[m_counter % 10]; + m_digits[1] = led_map[(m_counter / 10) % 10]; + m_digits[2] = led_map[high]; +} + +u8 cothello_state::coin_r() +{ + // d0-d2: coin status + // d3: ? + // d4-d7: unused + return m_counter_timer->enabled() ? 0xfb : 0xff; +} + u8 cothello_state::input_r() { u8 data = 0xff; @@ -106,14 +177,22 @@ u8 cothello_state::input_r() return data; } -u8 cothello_state::coin_r() -{ - return 0xfb; -} - void cothello_state::sound_w(u8 data) { - //printf("%X ",data); + if (data & 0x80) + { + // d3: beeper start + if (data & 8) + { + m_beeper->set_state(1); + m_beeper_off->adjust(attotime::from_msec(80)); + } + + // d0-d2: beeper frequency + u8 freq = (data & 0x7) + 1; + const u32 base = 3500; + m_beeper->set_clock(base / freq); + } } @@ -164,6 +243,21 @@ static INPUT_PORTS_START( cothello ) PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL PORT_NAME("P2 Pass") PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL PORT_NAME("P2 Set") PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED ) + + PORT_START("IN.3") + PORT_CONFNAME( 0x0f, 0x05, "Time" ) + PORT_DIPSETTING( 0x01, "100 seconds" ) + PORT_DIPSETTING( 0x02, "200 seconds" ) + PORT_DIPSETTING( 0x03, "300 seconds" ) + PORT_DIPSETTING( 0x04, "400 seconds" ) + PORT_DIPSETTING( 0x05, "500 seconds" ) + PORT_DIPSETTING( 0x06, "600 seconds" ) + PORT_DIPSETTING( 0x07, "700 seconds" ) + PORT_DIPSETTING( 0x08, "800 seconds" ) + PORT_DIPSETTING( 0x09, "900 seconds" ) + + PORT_START("COIN") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED_MEMBER(DEVICE_SELF, cothello_state, insert_coin, 0) INPUT_PORTS_END @@ -176,7 +270,6 @@ void cothello_state::cothello(machine_config &config) { // basic machine hardware I8080A(config, m_maincpu, 750000); - m_maincpu->set_vblank_int("screen", FUNC(cothello_state::irq0_line_hold)); m_maincpu->set_addrmap(AS_PROGRAM, &cothello_state::main_map); // video hardware @@ -188,6 +281,8 @@ void cothello_state::cothello(machine_config &config) m_screen->set_screen_update(FUNC(cothello_state::screen_update)); // sound hardware + SPEAKER(config, "mono").front_center(); + BEEP(config, m_beeper, 0).add_route(ALL_OUTPUTS, "mono", 0.25); } @@ -212,4 +307,4 @@ ROM_END ******************************************************************************/ // YEAR NAME PARENT MACHINE INPUT CLASS INIT SCREEN COMPANY, FULLNAME, FLAGS -GAMEL(1978, cothello, 0, cothello, cothello, cothello_state, empty_init, ROT0, "Nintendo", "Computer Othello", MACHINE_SUPPORTS_SAVE | MACHINE_NOT_WORKING | MACHINE_NO_SOUND, layout_cothello ) +GAMEL(1978, cothello, 0, cothello, cothello, cothello_state, empty_init, ROT0, "Nintendo", "Computer Othello", MACHINE_SUPPORTS_SAVE | MACHINE_NOT_WORKING | MACHINE_IMPERFECT_SOUND, layout_cothello ) -- cgit v1.2.3