1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 #ifndef MAME_INCLUDES_HX20_H
4 #define MAME_INCLUDES_HX20_H
5 
6 #pragma once
7 
8 #include "cpu/m6800/m6801.h"
9 #include "imagedev/cassette.h"
10 #include "machine/mc146818.h"
11 #include "machine/ram.h"
12 #include "sound/spkrdev.h"
13 #include "video/upd7227.h"
14 
15 #include "bus/generic/slot.h"
16 #include "bus/generic/carts.h"
17 #include "bus/epson_sio/epson_sio.h"
18 #include "bus/rs232/rs232.h"
19 
20 #include "emupal.h"
21 
22 #define HD6301V1_MAIN_TAG   "8g"
23 #define HD6301V1_SLAVE_TAG  "6d"
24 #define MC146818_TAG        "6g"
25 #define CASSETTE_TAG        "cassette"
26 #define RS232_TAG           "rs232"
27 #define SCREEN_TAG          "screen"
28 
29 class hx20_state : public driver_device
30 {
31 public:
hx20_state(const machine_config & mconfig,device_type type,const char * tag)32 	hx20_state(const machine_config &mconfig, device_type type, const char *tag)
33 		: driver_device(mconfig, type, tag)
34 		, m_maincpu(*this, HD6301V1_MAIN_TAG)
35 		, m_subcpu(*this, HD6301V1_SLAVE_TAG)
36 		, m_rtc(*this, MC146818_TAG)
37 		, m_lcdc(*this, "lcdc%u", 0U)
38 		, m_speaker(*this, "speaker")
39 		, m_cassette(*this, CASSETTE_TAG)
40 		, m_rs232(*this, RS232_TAG)
41 		, m_sio(*this, "sio")
42 		, m_optrom(*this, "optrom")
43 		, m_ksc_io(*this, "KSC%u", 0U)
44 		, m_sw6(*this, "SW6")
45 		, m_slave_rx(1)
46 		, m_slave_tx(1)
47 		, m_slave_flag(1)
48 		, m_rtc_irq(CLEAR_LINE)
49 		, m_kbrequest(1)
50 	{ }
51 
52 	void hx20(machine_config &config);
53 	void cm6032(machine_config &config);
54 	void cm6127(machine_config &config);
55 
56 private:
57 	required_device<hd6301v1_cpu_device> m_maincpu;
58 	required_device<hd6301v1_cpu_device> m_subcpu;
59 	required_device<mc146818_device> m_rtc;
60 	required_device_array<upd7227_device, 6> m_lcdc;
61 	required_device<speaker_sound_device> m_speaker;
62 	required_device<cassette_image_device> m_cassette;
63 	required_device<rs232_port_device> m_rs232;
64 	required_device<epson_sio_device> m_sio;
65 	optional_device<generic_slot_device> m_optrom;
66 	required_ioport_array<8> m_ksc_io;
67 	required_ioport m_sw6;
68 
69 	virtual void machine_start() override;
70 	void hx20_palette(palette_device &palette) const;
71 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
72 
73 	void ksc_w(uint8_t data);
74 	uint8_t krtn07_r();
75 	uint8_t krtn89_r();
76 	void lcd_cs_w(uint8_t data);
77 	void lcd_data_w(uint8_t data);
78 
79 	uint8_t main_p1_r();
80 	void main_p1_w(uint8_t data);
81 	uint8_t main_p2_r();
82 	void main_p2_w(uint8_t data);
83 
84 	uint8_t slave_p1_r();
85 	void slave_p1_w(uint8_t data);
86 	uint8_t slave_p2_r();
87 	void slave_p2_w(uint8_t data);
88 	uint8_t slave_p3_r();
89 	void slave_p3_w(uint8_t data);
90 	uint8_t slave_p4_r();
91 	void slave_p4_w(uint8_t data);
92 
93 	DECLARE_WRITE_LINE_MEMBER( rtc_irq_w );
94 
DECLARE_WRITE_LINE_MEMBER(sio_rx_w)95 	DECLARE_WRITE_LINE_MEMBER( sio_rx_w ) { m_sio_rx = state; }
DECLARE_WRITE_LINE_MEMBER(sio_pin_w)96 	DECLARE_WRITE_LINE_MEMBER( sio_pin_w ) { m_sio_pin = state; }
97 
98 	DECLARE_DEVICE_IMAGE_LOAD_MEMBER( optrom_load );
99 	uint8_t optrom_r(offs_t offset);
100 
101 	void update_interrupt();
102 
103 	// CPU state
104 	int m_slave_sio;
105 	int m_slave_rx;
106 	int m_slave_tx;
107 	int m_slave_flag;
108 	int m_rtc_irq;
109 
110 	// keyboard state
111 	uint8_t m_ksc;
112 	int m_kbrequest;
113 
114 	// video state
115 	uint8_t m_lcd_data;
116 
117 	// sio state
118 	int m_sio_rx;
119 	int m_sio_pin;
120 
121 	void hx20_mem(address_map &map);
122 	void hx20_sub_mem(address_map &map);
123 	void cm6032_mem(address_map &map);
124 	void cm6127_mem(address_map &map);
125 };
126 
127 #endif // MAME_INCLUDES_HX20_H
128