summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/rs232/xvd701.cpp
blob: 9b032606ea805c7760ba3edc8408fa60d9fe3df3 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// license:BSD-3-Clause
// copyright-holders:smf
#include "xvd701.h"

jvc_xvd701_device::jvc_xvd701_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, JVC_XVD701, "JVC XV-D701", tag, owner, clock, "xvd701", __FILE__),
	device_serial_interface(mconfig, *this),
	device_rs232_port_interface(mconfig, *this),
	m_response_index(0),
	m_timer_response(nullptr)
{
}

static MACHINE_CONFIG_FRAGMENT(xvd701)
MACHINE_CONFIG_END

machine_config_constructor jvc_xvd701_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME(xvd701);
}

static INPUT_PORTS_START(xvd701)
INPUT_PORTS_END

ioport_constructor jvc_xvd701_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(xvd701);
}

void jvc_xvd701_device::device_start()
{
	int startbits = 1;
	int databits = 8;
	parity_t parity = PARITY_ODD;
	stop_bits_t stopbits = STOP_BITS_1;

	set_data_frame(startbits, databits, parity, stopbits);

	int txbaud = 9600;
	set_tra_rate(txbaud);

	int rxbaud = 9600;
	set_rcv_rate(rxbaud);

	output_rxd(1);

	// TODO: make this configurable
	output_dcd(0);
	output_dsr(0);
	output_ri(0);
	output_cts(0);

	m_timer_response = timer_alloc(TIMER_RESPONSE);
}

void jvc_xvd701_device::device_reset()
{
	memset(m_command, 0, sizeof(m_command));

	m_response_index = sizeof(m_response);
}

void jvc_xvd701_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
	case TIMER_RESPONSE:
		send_response();
		break;

	default:
		device_serial_interface::device_timer(timer, id, param, ptr);
	}
}

void jvc_xvd701_device::tra_callback()
{
	output_rxd(transmit_register_get_data_bit());
}

void jvc_xvd701_device::tra_complete()
{
	m_timer_response->adjust(attotime::from_msec(100));
}

unsigned char jvc_xvd701_device::sum(unsigned char *buffer, int length)
{
	int sum = 0;

	for (int i = 0; i < length; i++)
		sum += buffer[i];

	return sum & 0x7f;
}

void jvc_xvd701_device::send_response()
{
	if (m_response_index < sizeof(m_response) && is_transmit_register_empty())
	{
//      printf("sending %02x\n", m_response[m_response_index]);
		transmit_register_setup(m_response[m_response_index++]);
	}
}

void jvc_xvd701_device::rcv_complete()
{
	receive_register_extract();

	for (int i = 0; i < sizeof(m_command) - 1; i++)
		m_command[i] = m_command[i + 1];

	m_command[sizeof(m_command) - 1] = get_received_char();

	if (m_command[0] == 0xff &&
		m_command[1] == 0xff &&
		m_command[2] == 0x21 &&
		sum(m_command, sizeof(m_command)) == 0)
	{
		// printf("xvd701");

		//for (int i = 0; i < sizeof(m_command); i++)
		//  printf(" %02x", m_command[i]);

		//printf("\n");

		// FF FF 21 3E 40 70 00 00 00 00 73 DEVICE ON
		// FF FF 21 3E 40 60 00 00 00 00 03 DEVICE OFF
		// FF FF 21 0C 44 60 00 00 00 00 31 STOP
		// FF FF 21 0C 43 75 00 00 00 00 1D PLAY
		// FF FF 21 0C 43 6D 00 00 00 00 25 PAUSE
		// FF FF 21 0C 50 20 00 00 00 00 63 SEEK TO SPECIFIC CHAPTER
		// FF FF 21 0C 50 73 00 00 00 00 12 FF (SEEK TO NEXT CHAPTER)
		// FF FF 21 0C 50 61 00 00 00 00 24 PREV (SEEK TO PREVIOUS CHAPTER)

		m_response[0] = 0xff;
		m_response[1] = 0xfe;
		m_response[2] = 0x7f;
		m_response[3] = 0x7e;
		m_response[4] = 0x7d;
		m_response[5] = 0x7c;
		m_response[6] = 0x7b;
		m_response[7] = 0x7a;
		m_response[8] = 0x79;
		m_response[9] = 0x78;
		m_response[10] = 0x77;
		m_response_index = 0;

		m_timer_response->adjust(attotime::from_msec(100));
	}
}

const device_type JVC_XVD701 = &device_creator<jvc_xvd701_device>;