summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/myb3k_kbd.h
blob: 747289a53f1f14cc1503ecbe9703216845628dd3 (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
// license:BSD-3-Clause
// copyright-holders:Fredrik Öhrström
/**********************************************************************

    myb3k_kbd.h

    Matsushita My Brain 3000 -- Panasonic JB-3000 -- Ericsson Step/One
    keyboard emulation.

    The keyboard 8048 ROM is not currently available, therefore it
    does not emulate the serial communication to the host computer.

    Instead the full byte is sent to the callback. The callback
    is responsible for storing the byte into the serial/parallell converter
    (that can be read through IN from port 0x04) and then trigger an interrupt.

    MCFG_DEVICE_ADD("myb3k_keyboard", MYB3K_KEYBOARD, 0)
    MCFG_MYB3K_KEYBOARD_CB(PUT(myb3k_state, kbd_set_data_and_interrupt))

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

#ifndef MAME_MACHINE_MYB3K_KBD_H
#define MAME_MACHINE_MYB3K_KBD_H

#pragma once

#define MYB3K_KBD_CB_PUT(cls, fnc)          myb3k_keyboard_device::output_delegate((&cls::fnc), (#cls "::" #fnc), DEVICE_SELF, ((cls *)nullptr))
#define MYB3K_KBD_CB_DEVPUT(tag, cls, fnc)  myb3k_keyboard_device::output_delegate((&cls::fnc), (#cls "::" #fnc), (tag), ((cls *)nullptr))

#define MCFG_MYB3K_KEYBOARD_CB(cb)          downcast<myb3k_keyboard_device &>(*device).set_keyboard_callback((MYB3K_KBD_CB_##cb));

DECLARE_DEVICE_TYPE(MYB3K_KEYBOARD, myb3k_keyboard_device)
DECLARE_DEVICE_TYPE(JB3000_KEYBOARD, jb3000_keyboard_device)
DECLARE_DEVICE_TYPE(STEPONE_KEYBOARD, stepone_keyboard_device)

class myb3k_keyboard_device : public device_t
{
public:
	typedef device_delegate<void (u8)> output_delegate;

	myb3k_keyboard_device(
			const machine_config &mconfig,
			const char *tag,
			device_t *owner,
			u32 clock);

	enum
	{
		TIMER_ID_SCAN_KEYS,
		TIMER_ID_FIRST_BYTE,
		TIMER_ID_SECOND_BYTE
	};

	template <class Object> void set_keyboard_callback(Object &&cb) { m_keyboard_cb = std::forward<Object>(cb); }

protected:
	myb3k_keyboard_device(
			const machine_config &mconfig,
			device_type type,
			char const *tag,
			device_t *owner,
			u32 clock);
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void send_byte(u8 code);
	void key_changed(int x, int y, bool down);
	void scan_keys();
	void update_modifiers(int y, bool down);
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;

	output_delegate             m_keyboard_cb;
	required_ioport_array<12>   m_io_kbd_t;
	u8                          m_io_kbd_state[12][8];

	int m_x, m_y;
	u8 m_first_byte;
	u8 m_second_byte;
	u8 m_modifier_keys;
};

class jb3000_keyboard_device : public myb3k_keyboard_device
{
public:
	 jb3000_keyboard_device(
		 const machine_config &mconfig,
		 char const *tag,
		 device_t *owner,
		 u32 clock);
private:
	virtual ioport_constructor device_input_ports() const override;
};

class stepone_keyboard_device : public myb3k_keyboard_device
{
public:
	 stepone_keyboard_device(
		 const machine_config &mconfig,
		 char const *tag,
		 device_t *owner,
		 u32 clock);
private:
	virtual ioport_constructor device_input_ports() const override;
};

#endif // MAME_MACHINE_MYB3K_KBD_H