summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/imagedev/floppy.h
blob: 5ac4f0de9a7348a69fa3b7507f436442a6e63f74 (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
/*********************************************************************

    floppy.h

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

#ifndef FLOPPY_H
#define FLOPPY_H

#include "formats/flopimg.h"

/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/
// ======================> floppy_interface

struct floppy_interface
{
	devcb_write_line 				m_out_idx_cb;  /* index */

	const struct floppy_format_def *m_formats;
	const char *					m_interface;
	device_image_display_info_func	m_device_displayinfo;
	device_image_load_func			m_load_func;
	device_image_unload_func		m_unload_func;
};

// ======================> cdrom_image_device

class floppy_image_device :	public device_t,
							public floppy_interface,
							public device_image_interface
{
public:
	// construction/destruction
	floppy_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	virtual ~floppy_image_device();

	// image-level overrides
	virtual bool call_load();
	virtual void call_unload();
	virtual void call_display_info() { if (m_device_displayinfo) m_device_displayinfo(*this); }
	virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); }

	virtual iodevice_t image_type() const { return IO_FLOPPY; }

	virtual bool is_readable()  const { return 1; }
	virtual bool is_writeable() const { return 1; }
	virtual bool is_creatable() const { return 0; }
	virtual bool must_be_loaded() const { return 0; }
	virtual bool is_reset_on_load() const { return 0; }
	virtual const char *image_interface() const { return m_interface; }
	virtual const char *file_extensions() const { return m_extension_list; }
	virtual const option_guide *create_option_guide() const { return NULL; }

	UINT8* get_buffer() { return m_image->get_buffer(m_cyl,m_ss ^ 1); }
	
	void mon_w(int state);
	void index_func();
	int  ready_r();
	double get_pos();
	
	int wpt_r() { return m_wpt; }
	int dskchg_r() { return m_dskchg; }
	int trk00_r() { return (m_cyl==0) ? 0 : 1; }
	
	void stp_w(int state); 
	void dir_w(int state) { m_dir = state; }
	void ss_w(int state) { m_ss = state; } 

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

	image_device_format m_format;
	floppy_image 		*m_image;
	char				m_extension_list[256];
	
	/* index pulse timer */
	emu_timer	*m_index_timer;
	
	/* state of input lines */
	int m_dir;  /* direction */
	int m_stp;  /* step */
	int m_wtg;  /* write gate */
	int m_mon;  /* motor on */
	int m_ss;	/* side select */

	/* state of output lines */
	int m_idx;  /* index pulse */
	int m_tk00; /* track 00 */
	int m_wpt;  /* write protect */
	int m_rdy;  /* ready */
	int m_dskchg;		/* disk changed */
	
	/* rotation per minute => gives index pulse frequency */
	float m_rpm;
	
	int m_cyl;
	devcb_resolved_write_line m_out_idx_func;
};

// device type definition
extern const device_type FLOPPY;

/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/
#define FLOPPY_0 "floppy0"
#define FLOPPY_1 "floppy1"
#define FLOPPY_2 "floppy2"
#define FLOPPY_3 "floppy3"

#define MCFG_FLOPPY_DRIVE_ADD(_config) \
	MCFG_DEVICE_ADD(FLOPPY_0, FLOPPY, 0) \
	MCFG_DEVICE_CONFIG(_config)	\

#define MCFG_FLOPPY_2_DRIVES_ADD(_config)	\
	MCFG_DEVICE_ADD(FLOPPY_0, FLOPPY, 0)		\
	MCFG_DEVICE_CONFIG(_config)	\
	MCFG_DEVICE_ADD(FLOPPY_1, FLOPPY, 0)		\
	MCFG_DEVICE_CONFIG(_config)

#endif /* FLOPPY_H */