1 // license:BSD-3-Clause 2 // copyright-holders:hap 3 /****************************************************************************** 4 * 5 * Chess King chess computer driver base class 6 * 7 ******************************************************************************/ 8 9 #pragma once 10 11 #ifndef MAME_INCLUDES_CKINGBASE_H 12 #define MAME_INCLUDES_CKINGBASE_H 13 14 #include "machine/timer.h" 15 16 class ckingbase_state : public driver_device 17 { 18 public: ckingbase_state(const machine_config & mconfig,device_type type,const char * tag)19 ckingbase_state(const machine_config &mconfig, device_type type, const char *tag) : 20 driver_device(mconfig, type, tag), 21 m_maincpu(*this, "maincpu"), 22 m_irq_on(*this, "irq_on"), 23 m_inp_matrix(*this, "IN.%u", 0), 24 m_out_x(*this, "%u.%u", 0U, 0U), 25 m_out_a(*this, "%u.a", 0U), 26 m_out_digit(*this, "digit%u", 0U), 27 m_display_wait(33), 28 m_display_maxy(1), 29 m_display_maxx(0) 30 { } 31 32 // devices/pointers 33 required_device<cpu_device> m_maincpu; 34 optional_device<timer_device> m_irq_on; 35 optional_ioport_array<10> m_inp_matrix; // max 10 36 output_finder<0x20, 0x20> m_out_x; 37 output_finder<0x20> m_out_a; 38 output_finder<0x20> m_out_digit; 39 40 // misc common 41 u16 m_inp_mux; // multiplexed keypad mask 42 u16 m_led_select; 43 u16 m_led_data; 44 45 u16 read_inputs(int columns); 46 47 // periodic interrupts TIMER_DEVICE_CALLBACK_MEMBER(irq_on)48 template<int Line> TIMER_DEVICE_CALLBACK_MEMBER(irq_on) { m_maincpu->set_input_line(Line, ASSERT_LINE); } TIMER_DEVICE_CALLBACK_MEMBER(irq_off)49 template<int Line> TIMER_DEVICE_CALLBACK_MEMBER(irq_off) { m_maincpu->set_input_line(Line, CLEAR_LINE); } 50 51 // display common 52 int m_display_wait; // led/lamp off-delay in milliseconds (default 33ms) 53 int m_display_maxy; // display matrix number of rows 54 int m_display_maxx; // display matrix number of columns (max 31 for now) 55 56 u32 m_display_state[0x20]; // display matrix rows data (last bit is used for always-on) 57 u16 m_display_segmask[0x20]; // if not 0, display matrix row is a digit, mask indicates connected segments 58 u8 m_display_decay[0x20][0x20]; // (internal use) 59 60 TIMER_DEVICE_CALLBACK_MEMBER(display_decay_tick); 61 void display_update(); 62 void set_display_size(int maxx, int maxy); 63 void display_matrix(int maxx, int maxy, u32 setx, u32 sety, bool update = true); 64 65 protected: 66 virtual void machine_start() override; 67 virtual void machine_reset() override; 68 }; 69 70 71 INPUT_PORTS_EXTERN( cking_cb_buttons ); 72 73 #endif // MAME_INCLUDES_CKINGBASE_H 74