1 // license:BSD-3-Clause
2 // copyright-holders:hap
3 /*
4 
5   Saitek Stratos family chess computers shared class
6   Used in: saitek_stratos.cpp (main driver), saitek_corona.cpp
7 
8 */
9 
10 #ifndef MAME_INCLUDES_SAITEK_STRATOS_H
11 #define MAME_INCLUDES_SAITEK_STRATOS_H
12 
13 #pragma once
14 
15 #include "video/pwm.h"
16 
17 #include <algorithm>
18 
19 
20 class saitek_stratos_state : public driver_device
21 {
22 public:
saitek_stratos_state(const machine_config & mconfig,device_type type,const char * tag)23 	saitek_stratos_state(const machine_config &mconfig, device_type type, const char *tag) :
24 		driver_device(mconfig, type, tag),
25 		m_maincpu(*this, "maincpu"),
26 		m_display(*this, "display"),
27 		m_out_digit(*this, "digit%u", 0U),
28 		m_out_lcd(*this, "lcd%u.%u.%u", 0U, 0U, 0U)
29 	{ }
30 
DECLARE_INPUT_CHANGED_MEMBER(switch_cpu_freq)31 	DECLARE_INPUT_CHANGED_MEMBER(switch_cpu_freq) { set_cpu_freq(); }
DECLARE_INPUT_CHANGED_MEMBER(acl_button)32 	DECLARE_INPUT_CHANGED_MEMBER(acl_button) { if (newval) power_off(); }
33 	DECLARE_INPUT_CHANGED_MEMBER(go_button);
34 
35 protected:
36 	virtual void machine_start() override;
37 	virtual void machine_reset() override;
device_post_load()38 	virtual void device_post_load() override { update_lcd(); }
39 
40 	// devices/pointers
41 	required_device<cpu_device> m_maincpu;
42 	required_device<pwm_display_device> m_display;
43 	output_finder<8+1> m_out_digit;
44 	output_finder<4, 16, 4> m_out_lcd;
45 
46 	// common handlers
clear_lcd()47 	void clear_lcd() { std::fill_n(m_lcd_data, ARRAY_LENGTH(m_lcd_data), 0); }
48 	void update_lcd();
49 	void power_off();
50 	void set_cpu_freq();
51 	void lcd_data_w(u8 data);
52 
53 	bool m_power;
54 	bool m_lcd_ready;
55 	u8 m_lcd_count;
56 	u8 m_lcd_command;
57 	u8 m_lcd_data[0x40];
58 };
59 
60 INPUT_PORTS_EXTERN( saitek_stratos );
61 
62 #endif // MAME_INCLUDES_SAITEK_STRATOS_H
63