apricot: Add mouse support

This commit is contained in:
Dirk Best 2019-02-08 14:15:19 +01:00
parent d39af83c55
commit 35cf6670f1
2 changed files with 88 additions and 2 deletions

View File

@ -6,7 +6,6 @@
TODO:
- MicroScreen emulation
- Mouse emulation
- LEDs
Keyboard to System:
@ -188,6 +187,17 @@ static INPUT_PORTS_START( keyboard )
PORT_START("row_c")
PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER_PAD) PORT_CHAR(UCHAR_MAMEKEY(ENTER_PAD))
PORT_START("mouse_b")
PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Mouse Right Button")
PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Left Button")
PORT_BIT(0x0c, IP_ACTIVE_HIGH, IPT_UNUSED)
PORT_START("mouse_x")
PORT_BIT(0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(75) PORT_KEYDELTA(5)
PORT_START("mouse_y")
PORT_BIT(0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(50) PORT_KEYDELTA(5)
INPUT_PORTS_END
ioport_constructor apricot_keyboard_hle_device::device_input_ports() const
@ -197,6 +207,8 @@ ioport_constructor apricot_keyboard_hle_device::device_input_ports() const
MACHINE_CONFIG_START(apricot_keyboard_hle_device::device_add_mconfig)
MCFG_DEVICE_ADD("rtc", MSM5832, 32.768_kHz_XTAL)
TIMER(config, "timer").configure_periodic(FUNC(apricot_keyboard_hle_device::mouse_callback), attotime::from_hz(60));
MACHINE_CONFIG_END
@ -214,7 +226,12 @@ apricot_keyboard_hle_device::apricot_keyboard_hle_device(const machine_config &m
device_buffered_serial_interface(mconfig, *this),
device_matrix_keyboard_interface(mconfig, *this, "row_0", "row_1", "row_2", "row_3", "row_4", "row_5", "row_6", "row_7", "row_8", "row_9", "row_a", "row_b", "row_c"),
m_rtc(*this, "rtc"),
m_rtc_index(0)
m_mouse_b(*this, "mouse_b"),
m_mouse_x(*this, "mouse_x"),
m_mouse_y(*this, "mouse_y"),
m_rtc_index(0),
m_mouse_enabled(false),
m_mouse_last_b(0), m_mouse_last_x(0), m_mouse_last_y(0)
{
}
@ -224,6 +241,12 @@ apricot_keyboard_hle_device::apricot_keyboard_hle_device(const machine_config &m
void apricot_keyboard_hle_device::device_start()
{
// register for save states
save_item(NAME(m_rtc_index));
save_item(NAME(m_mouse_enabled));
save_item(NAME(m_mouse_last_b));
save_item(NAME(m_mouse_last_x));
save_item(NAME(m_mouse_last_y));
}
//-------------------------------------------------
@ -308,6 +331,16 @@ void apricot_keyboard_hle_device::received_byte(uint8_t byte)
break;
case CMD_ENABLE_MOUSE:
logerror("System enables mouse\n");
m_mouse_enabled = true;
break;
case CMD_DISABLE_MOUSE:
logerror("System disables mouse\n");
m_mouse_enabled = false;
break;
case CMD_KEYBOARD_RESET:
logerror("System requests keyboard reset\n");
transmit_byte(ACK_DIAGNOSTICS);
@ -347,3 +380,44 @@ void apricot_keyboard_hle_device::out_w(int state)
{
device_buffered_serial_interface::rx_w(state);
}
//-------------------------------------------------
// mouse_callback - check for new mouse events
//-------------------------------------------------
TIMER_DEVICE_CALLBACK_MEMBER( apricot_keyboard_hle_device::mouse_callback )
{
if (m_mouse_enabled)
{
// get mouse state
uint8_t buttons = m_mouse_b->read();
uint8_t x = m_mouse_x->read();
uint8_t y = m_mouse_y->read();
// anything changed since last time?
if (buttons != m_mouse_last_b || x != m_mouse_last_x || y != m_mouse_last_y)
{
// mouse header
transmit_byte(0xef);
// button state
transmit_byte(0x70 | buttons);
int8_t dx = x - m_mouse_last_x;
int8_t dy = y - m_mouse_last_y;
// y direction change
transmit_byte(0x70 | ((dy >> 4) & 0x0f));
transmit_byte(0x70 | ((dy >> 0) & 0x0f));
// x direction change
transmit_byte(0x70 | ((dx >> 4) & 0x0f));
transmit_byte(0x70 | ((dx >> 0) & 0x0f));
// save mouse state for next run
m_mouse_last_b = buttons;
m_mouse_last_x = x;
m_mouse_last_y = y;
}
}
}

View File

@ -14,6 +14,7 @@
#include "keyboard.h"
#include "machine/keyboard.h"
#include "machine/msm5832.h"
#include "machine/timer.h"
#include "diserial.h"
@ -51,9 +52,13 @@ protected:
virtual void key_break(uint8_t row, uint8_t column) override;
private:
TIMER_DEVICE_CALLBACK_MEMBER(mouse_callback);
enum {
CMD_REQ_TIME_AND_DATE = 0xe1,
CMD_SET_TIME_AND_DATE = 0xe4,
CMD_ENABLE_MOUSE = 0xe5,
CMD_DISABLE_MOUSE = 0xe6,
CMD_KEYBOARD_RESET = 0xe8
};
@ -62,8 +67,15 @@ private:
};
required_device<msm5832_device> m_rtc;
required_ioport m_mouse_b;
required_ioport m_mouse_x;
required_ioport m_mouse_y;
int m_rtc_index;
bool m_mouse_enabled;
uint8_t m_mouse_last_b;
uint8_t m_mouse_last_x;
uint8_t m_mouse_last_y;
};