summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/ieee488/remote488.h
blob: 312fc260f423de3c30b487972ca156f0876c8d61 (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
// license:BSD-3-Clause
// copyright-holders: F. Ulivi
/*********************************************************************

    remote488.h

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

#ifndef MAME_BUS_IEEE488_REMOTE488_H
#define MAME_BUS_IEEE488_REMOTE488_H

#pragma once

#include "ieee488.h"
#include "imagedev/bitbngr.h"

class remote488_device : public device_t,
						 public device_ieee488_interface
{
public:
	// construction/destruction
	remote488_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// device_ieee488_interface overrides
	virtual void ieee488_eoi(int state) override;
	virtual void ieee488_dav(int state) override;
	virtual void ieee488_nrfd(int state) override;
	virtual void ieee488_ndac(int state) override;
	virtual void ieee488_ifc(int state) override;
	virtual void ieee488_srq(int state) override;
	virtual void ieee488_atn(int state) override;
	virtual void ieee488_ren(int state) override;

	// Timers
	enum {
		TMR_ID_POLL,
		TMR_ID_HEARTBEAT,
		TMR_ID_AH
	};

protected:
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;

private:
	// Position of signals in "S/R" msgs
	enum signal_bit {
		SIGNAL_ATN_BIT, // Bit 0
		SIGNAL_IFC_BIT, // Bit 1
		SIGNAL_REN_BIT, // Bit 2
		SIGNAL_SRQ_BIT, // Bit 3
		SIGNAL_COUNT
	};

	// Source handshake states
	enum {
		REM_SH_SIDS,
		REM_SH_SDYS,
		REM_SH_STRS
	};

	// Acceptor handshake states
	enum {
		REM_AH_AIDS,
		REM_AH_ACRS,
		REM_AH_ACDS,
		REM_AH_AWNS
	};

	// Stream rx states
	enum {
		REM_RX_WAIT_CH,
		REM_RX_WAIT_COLON,
		REM_RX_WAIT_1ST_HEX,
		REM_RX_WAIT_2ND_HEX,
		REM_RX_WAIT_SEP,
		REM_RX_WAIT_WS
	};

	required_device<bitbanger_device> m_stream;
	uint8_t m_in_signals;
	uint8_t m_out_signals;
	bool m_no_propagation;
	int m_sh_state;
	int m_ah_state;
	int m_rx_state;
	char m_rx_ch;
	uint8_t m_rx_data;
	bool m_flush_bytes;
	bool m_ibf;
	uint8_t m_ib;
	bool m_ib_eoi;
	emu_timer *m_poll_timer;
	emu_timer *m_hb_timer;
	emu_timer *m_ah_timer;
	unsigned m_connect_cnt;
	bool m_connected;
	uint8_t m_pp_data;
	bool m_pp_requested;
	uint8_t m_pp_dio;
	uint8_t m_sh_dio;
	bool m_waiting_cp;

	void bus_reset();
	void process_input_msgs();
	void set_connection(bool state);
	void recvd_data_byte(uint8_t data , bool eoi);
	void flush_data();
	void update_signals_from_rem(uint8_t to_set , uint8_t to_clear);
	void update_signal(signal_bit bit , int state);
	void update_state(uint8_t new_signals);
	void send_update(char type , uint8_t data);
	static bool a2hex(char c , uint8_t& out);
	static bool is_msg_type(char c);
	static bool is_terminator(char c);
	static bool is_space(char c);
	char recv_update(uint8_t& data);
	bool is_local_atn_active() const;
	void ah_checkpoint();
	void update_ah_fsm();
	void update_sh_fsm();
	bool is_local_pp_active() const;
	void update_pp();
	void update_pp_dio();
	void update_dio();
};

// device type definition
DECLARE_DEVICE_TYPE(REMOTE488, remote488_device)

#endif // MAME_BUS_IEEE488_REMOTE488_H