1 // license:BSD-3-Clause
2 // copyright-holders:smf,Carl
3 /*
4  * ds1205.h
5  *
6  * MultiKey
7  *
8  */
9 
10 #ifndef MAME_MACHINE_DS1205_H
11 #define MAME_MACHINE_DS1205_H
12 
13 #pragma once
14 
15 
16 class ds1205_device : public device_t, public device_nvram_interface
17 {
18 public:
19 	// construction/destruction
20 	ds1205_device( const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
21 
22 	DECLARE_WRITE_LINE_MEMBER( write_rst );
23 	DECLARE_WRITE_LINE_MEMBER( write_clk );
24 	DECLARE_WRITE_LINE_MEMBER( write_dq );
25 	DECLARE_READ_LINE_MEMBER( read_dq );
26 
27 protected:
28 	// device-level overrides
29 	virtual void device_start() override;
30 
31 	// device_nvram_interface overrides
32 	virtual void nvram_default() override;
33 	virtual void nvram_read( emu_file &file ) override;
34 	virtual void nvram_write( emu_file &file ) override;
35 
36 private:
37 	inline void ATTR_PRINTF( 3, 4 ) verboselog( int n_level, const char *s_fmt, ... );
38 	void new_state(int state);
39 	void writebit(u8 *buffer);
40 	void readbit(u8 *buffer);
41 
42 	enum state_t
43 	{
44 		STATE_STOP,
45 		STATE_PROTOCOL,
46 		STATE_READ_IDENTIFICATION,
47 		STATE_WRITE_IDENTIFICATION,
48 		STATE_WRITE_COMPARE_REGISTER,
49 		STATE_WRITE_SECURITY_MATCH,
50 		STATE_READ_DATA,
51 		STATE_WRITE_DATA,
52 		STATE_READ_SCRATCH,
53 		STATE_WRITE_SCRATCH,
54 		STATE_OUTPUT_GARBLED_DATA
55 	};
56 
57 	enum command_t
58 	{
59 		COMMAND_SET_SCRATCHPAD = 0x96,
60 		COMMAND_GET_SCRATCHPAD = 0x69,
61 		COMMAND_SET_DATA = 0x99,
62 		COMMAND_GET_DATA = 0x66,
63 		COMMAND_SET_SECURITY = 0x5a,
64 		COMMAND_MOVE_BLOCK = 0x3c
65 	};
66 
67 	enum cycle_t
68 	{
69 		CYCLE_NORMAL = 1,
70 		CYCLE_PROGRAM = 2,
71 		CYCLE_MASK = 3
72 	};
73 
74 	static const int DQ_HIGH_IMPEDANCE = -1;
75 
76 	optional_memory_region m_region;
77 
78 	int m_rst;
79 	int m_clk;
80 	int m_dqw;
81 	int m_dqr;
82 	int m_state;
83 	int m_bit;
84 	u8 m_command[3];
85 	u8 m_compare_register[8];
86 	u8 m_scratchpad[64];
87 	u8 m_identification[3][8];
88 	u8 m_security_match[3][8];
89 	u8 m_secure_memory[3][48];
90 };
91 
92 
93 // device type definition
94 DECLARE_DEVICE_TYPE(DS1205, ds1205_device)
95 
96 #endif // MAME_MACHINE_DS1205_H
97