summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/8042kbdc.h
blob: f2e7fdfbf04077ddfc4fe0245c8295e86a373322 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// license:BSD-3-Clause
// copyright-holders:Peter Trauner
/**********************************************************************

    8042 Keyboard Controller Emulation

    This is the keyboard controller used in the IBM AT and further
    models.  It is a popular controller for PC style keyboards

**********************************************************************/

#ifndef MAME_MACHINE_8042KBDC_H
#define MAME_MACHINE_8042KBDC_H

#pragma once

#include "machine/pckeybrd.h"

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> kbdc8042_device

class kbdc8042_device : public device_t
{
public:
	enum kbdc8042_type_t
	{
		KBDC8042_STANDARD,
		KBDC8042_PS2,       /* another timing of integrated controller */
		KBDC8042_AT386      /* hack for at386 driver */
	};

	// construction/destruction
	kbdc8042_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);

	void set_keyboard_type(kbdc8042_type_t keybtype) { m_keybtype = keybtype; }
	auto system_reset_callback() { return m_system_reset_cb.bind(); }
	auto gate_a20_callback() { return m_gate_a20_cb.bind(); }
	auto input_buffer_full_callback() { return m_input_buffer_full_cb.bind(); }
	auto output_buffer_empty_callback() { return m_output_buffer_empty_cb.bind(); }
	auto speaker_callback() { return m_speaker_cb.bind(); }

	DECLARE_READ8_MEMBER( data_r );
	DECLARE_WRITE8_MEMBER( data_w );

	DECLARE_WRITE_LINE_MEMBER( write_out2 );

	void at_8042_set_outport(uint8_t data, int initial);
	void at_8042_receive(uint8_t data, bool mouse = false);
	void at_8042_check_keyboard();
	void at_8042_check_mouse();
	void at_8042_clear_keyboard_received();

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

private:
	uint8_t m_inport;
	uint8_t m_outport;
	uint8_t m_data;
	uint8_t m_command;

	struct {
		int received;
		int on;
	} m_keyboard;
	struct {
		int received;
		int on;
		uint8_t sample_rate;
		bool receiving_sample_rate;
		uint8_t transmit_buf[8];
		uint8_t to_transmit;
	} m_mouse;

	int m_last_write_to_control;
	int m_sending;
	int m_send_to_mouse;

	int m_operation_write_state;
	int m_status_read_mode;

	int m_speaker;
	int m_out2;

	/* temporary hack */
	int m_offset1;

	int m_poll_delay;

	required_device<at_keyboard_device> m_keyboard_dev;
	required_ioport m_mousex_port;
	required_ioport m_mousey_port;
	required_ioport m_mousebtn_port;

	kbdc8042_type_t     m_keybtype;

	devcb_write_line    m_system_reset_cb;
	devcb_write_line    m_gate_a20_cb;
	devcb_write_line    m_input_buffer_full_cb;
	devcb_write_line    m_output_buffer_empty_cb;

	devcb_write8        m_speaker_cb;

	uint16_t            m_mouse_x;
	uint16_t            m_mouse_y;
	uint8_t             m_mouse_btn;

	DECLARE_WRITE_LINE_MEMBER( keyboard_w );
};

// device type definition
DECLARE_DEVICE_TYPE(KBDC8042, kbdc8042_device)

#endif // MAME_MACHINE_8042KBDC_H