1 // license:BSD-3-Clause
2 // copyright-holders:Patrick Mackinlay
3 
4 #ifndef MAME_VIDEO_BT431_H
5 #define MAME_VIDEO_BT431_H
6 
7 #pragma once
8 
9 class bt431_device : public device_t
10 {
11 public:
12 	bt431_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);
13 
14 	enum register_number : unsigned
15 	{
16 		REG_COMMAND     =  0,
17 		REG_CURSOR_X_LO =  1,
18 		REG_CURSOR_X_HI =  2,
19 		REG_CURSOR_Y_LO =  3,
20 		REG_CURSOR_Y_HI =  4,
21 		REG_WINDOW_X_LO =  5,
22 		REG_WINDOW_X_HI =  6,
23 		REG_WINDOW_Y_LO =  7,
24 		REG_WINDOW_Y_HI =  8,
25 		REG_WINDOW_W_LO =  9,
26 		REG_WINDOW_W_HI = 10,
27 		REG_WINDOW_H_LO = 11,
28 		REG_WINDOW_H_HI = 12,
29 	};
30 
31 	enum command_mask : u8
32 	{
33 		CR_D1D0 = 0x03, // cross hair cursor thickness
34 		CR_D3D2 = 0x0c, // multiplex control
35 		CR_D4   = 0x10, // cursor format control
36 		CR_D5   = 0x20, // cross hair cursor enable
37 		CR_D6   = 0x40, // 64x64 cursor enable
38 
39 		CR_WM   = 0x7f, // write mask
40 	};
41 
42 	enum cr_d1d0_mask : u8
43 	{
44 		CR_D1D0_1PIX = 0x00, // 1 pixel
45 		CR_D1D0_3PIX = 0x01, // 3 pixels
46 		CR_D1D0_5PIX = 0x02, // 5 pixels
47 		CR_D1D0_7PIX = 0x03, // 7 pixels
48 	};
49 	enum cr_d3d2_mask : u8
50 	{
51 		CR_D3D2_11 = 0x00, // 1:1 multiplexing
52 		CR_D3D2_41 = 0x04, // 4:1 multiplexing
53 		CR_D3D2_51 = 0x08, // 5:1 multiplexing
54 	};
55 
56 	void map(address_map &map);
57 	bool cur_r(unsigned x, unsigned y) const;
58 
59 protected:
60 	static constexpr u16 ADDRESS_MASK = 0x01ff;
61 
62 	// device_t overrides
63 	virtual void device_start() override;
64 	virtual void device_reset() override;
65 
addr_r()66 	template <unsigned S> u8 addr_r() { return m_address >> S; }
addr_w(u8 data)67 	template <unsigned S> void addr_w(u8 data) { m_address = ((m_address & (0xff00 >> S)) | (u16(data) << S)) & ADDRESS_MASK; }
68 
69 	u8 ram_r();
70 	void ram_w(u8 data);
71 
72 	u8 reg_r();
73 	void reg_w(u8 data);
74 
75 private:
76 	void update();
77 
78 	// registers
79 	u16 m_address;
80 	u8 m_command;
81 	u16 m_cursor_x;
82 	u16 m_cursor_y;
83 	u16 m_window_x;
84 	u16 m_window_y;
85 	u16 m_window_w;
86 	u16 m_window_h;
87 
88 	u8 m_ram[512];
89 
90 	rectangle m_bm_window;
91 	rectangle m_ch_h;
92 	rectangle m_ch_v;
93 };
94 
95 DECLARE_DEVICE_TYPE(BT431, bt431_device)
96 
97 #endif // MAME_VIDEO_BT431_H
98