summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/compclr_flp.h
blob: 3bbdeb790064bbe5e19de95e52e0dc6a2d50f77a (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Compucolor Floppy Disk Drive emulation

    Copyright MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

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

#pragma once

#ifndef __COMPCLR_FLP__
#define __COMPCLR_FLP__

#include "emu.h"
#include "formats/ccvf_dsk.h"
#include "imagedev/floppy.h"
#include "machine/serial.h"



//**************************************************************************
//  INTERFACE MACROS
//**************************************************************************

#define MCFG_COMPUCOLOR_FLOPPY_PORT_ADD(_tag, _slot_intf, _def_slot) \
	MCFG_DEVICE_ADD(_tag, COMPUCOLOR_FLOPPY_PORT, 0) \
	MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)



//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> device_compucolor_floppy_port_interface

class device_compucolor_floppy_port_interface : public device_serial_port_interface
{
public:
	device_compucolor_floppy_port_interface(const machine_config &mconfig, device_t &device);
	virtual ~device_compucolor_floppy_port_interface() { }

	virtual void rw_w(int state) = 0;
	virtual void stepper_w(UINT8 data) = 0;
	virtual void select_w(int state) = 0;
};


// ======================> compucolor_floppy_port_device

class compucolor_floppy_port_device : public serial_port_device
{
public:
	compucolor_floppy_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	virtual ~compucolor_floppy_port_device() { }

	DECLARE_WRITE_LINE_MEMBER( rw_w ) { if (m_dev) m_dev->rw_w(state); }
	void stepper_w(UINT8 data) { if (m_dev) m_dev->stepper_w(data); }
	DECLARE_WRITE_LINE_MEMBER( select_w ) { if (m_dev) m_dev->select_w(state); }

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_config_complete();

private:
	device_compucolor_floppy_port_interface *m_dev;
};


// ======================> compucolor_floppy_device

class compucolor_floppy_device : public device_t,
								 public device_compucolor_floppy_port_interface
{
public:
	// construction/destruction
	compucolor_floppy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	DECLARE_FLOPPY_FORMATS( floppy_formats );

	// optional information overrides
	virtual machine_config_constructor device_mconfig_additions() const;

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	// device_serial_port_interface overrides
	virtual void tx(UINT8 state);

	// device_compucolor_floppy_port_interface overrides
	virtual void rw_w(int state);
	virtual void stepper_w(UINT8 data);
	virtual void select_w(int state);

private:
	required_device<floppy_image_device> m_floppy;

	bool read_bit();
	void write_bit(bool bit);

	int m_rw;
	int m_stp;
	int m_sel;

	attotime m_period;

	compucolor_floppy_port_device *m_owner;

	emu_timer *m_timer;
};


// device type definition
extern const device_type COMPUCOLOR_FLOPPY_PORT;
extern const device_type COMPUCOLOR_FLOPPY;


// slot devices
SLOT_INTERFACE_EXTERN( compucolor_floppy_port_devices );



#endif