summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/upd765.h
blob: 291dda6868a8938bbf56287fa55116afb3178348 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/***************************************************************************

    machine/upd765.h

    Functions to emulate a NEC upd765/Intel 8272 compatible
    floppy disk controller

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

#ifndef __UPD765_H__
#define __UPD765_H__

#include "devcb.h"
#include "imagedev/flopdrv.h"


/***************************************************************************
    MACROS
***************************************************************************/

class upd765a_device : public device_t
{
public:
	upd765a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	upd765a_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
	~upd765a_device() { global_free(m_token); }

	// access to legacy token
	void *token() const { assert(m_token != NULL); return m_token; }
protected:
	// device-level overrides
	virtual void device_config_complete();
	virtual void device_start();
	virtual void device_reset();
private:
	// internal state
	void *m_token;
};

extern const device_type UPD765A;

class upd765b_device : public upd765a_device
{
public:
	upd765b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
	// device-level overrides
	virtual void device_start();
};

extern const device_type UPD765B;

class smc37c78_device : public upd765a_device
{
public:
	smc37c78_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
	// device-level overrides
	virtual void device_start();
};

extern const device_type SMC37C78;

class upd72065_device : public upd765a_device
{
public:
	upd72065_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
	// device-level overrides
	virtual void device_start();
};

extern const device_type UPD72065;


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

/* RDY pin connected state */
enum UPD765_RDY_PIN
{
	UPD765_RDY_PIN_NOT_CONNECTED = 0,
	UPD765_RDY_PIN_CONNECTED = 1
};

#define UPD765_DAM_DELETED_DATA 0x0f8
#define UPD765_DAM_DATA 0x0fb

typedef device_t *(*upd765_get_image_func)(device_t *device, int floppy_index);
#define UPD765_GET_IMAGE(name)	device_t *name(device_t *device, int floppy_index )


struct upd765_interface
{
	/* interrupt issued */
	devcb_write_line out_int_func;

	/* dma data request */
	devcb_write_line out_drq_func;

	/* image lookup */
	upd765_get_image_func get_image;

	UPD765_RDY_PIN rdy_pin;

	const char *floppy_drive_tags[4];
};


/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

/* read of data register */
READ8_DEVICE_HANDLER(upd765_data_r);
/* write to data register */
WRITE8_DEVICE_HANDLER(upd765_data_w);
/* read of main status register */
READ8_DEVICE_HANDLER(upd765_status_r);

/* dma acknowledge with write */
WRITE8_DEVICE_HANDLER(upd765_dack_w);
/* dma acknowledge with read */
READ8_DEVICE_HANDLER(upd765_dack_r);

/* reset upd765 */
void upd765_reset(device_t *device, int);

/* reset pin of upd765 */
WRITE_LINE_DEVICE_HANDLER(upd765_reset_w);

/* set upd765 terminal count input state */
WRITE_LINE_DEVICE_HANDLER(upd765_tc_w);

/* set upd765 ready input*/
WRITE_LINE_DEVICE_HANDLER(upd765_ready_w);

void upd765_idle(device_t *device);
void upd765_set_bad(device_t *device, int state);

READ_LINE_DEVICE_HANDLER( upd765_int_r );
READ_LINE_DEVICE_HANDLER( upd765_drq_r );

/*********************/
/* STATUS REGISTER 1 */

/* this is set if a TC signal was not received after the sector data was read */
#define UPD765_ST1_END_OF_CYLINDER (1<<7)
/* this is set if the sector ID being searched for is not found */
#define UPD765_ST1_NO_DATA (1<<2)
/* set if disc is write protected and a write/format operation was performed */
#define UPD765_ST1_NOT_WRITEABLE (1<<1)

/*********************/
/* STATUS REGISTER 2 */

/* C parameter specified did not match C value read from disc */
#define UPD765_ST2_WRONG_CYLINDER (1<<4)
/* C parameter specified did not match C value read from disc, and C read from disc was 0x0ff */
#define UPD765_ST2_BAD_CYLINDER (1<<1)
/* this is set if the FDC encounters a Deleted Data Mark when executing a read data
command, or FDC encounters a Data Mark when executing a read deleted data command */
#define UPD765_ST2_CONTROL_MARK (1<<6)

/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_UPD765A_ADD(_tag, _intrf) \
	MCFG_DEVICE_ADD(_tag, UPD765A, 0) \
	MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD765A_MODIFY(_tag, _intrf) \
  MCFG_DEVICE_MODIFY(_tag)	      \
  MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD765A_REMOVE(_tag)		\
  MCFG_DEVICE_REMOVE(_tag)

#define MCFG_UPD765B_ADD(_tag, _intrf) \
	MCFG_DEVICE_ADD(_tag, UPD765B, 0) \
	MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD765B_MODIFY(_tag, _intrf) \
  MCFG_DEVICE_MODIFY(_tag)	      \
  MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD765B_REMOVE(_tag)		\
  MCFG_DEVICE_REMOVE(_tag)

#define MCFG_SMC37C78_ADD(_tag, _intrf) \
	MCFG_DEVICE_ADD(_tag, SMC37C78, 0) \
	MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_SMC37C78_MODIFY(_tag, _intrf) \
  MCFG_DEVICE_MODIFY(_tag)	      \
  MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_SMC37C78_REMOVE(_tag)		\
  MCFG_DEVICE_REMOVE(_tag)

#define MCFG_UPD72065_ADD(_tag, _intrf) \
	MCFG_DEVICE_ADD(_tag, UPD72065, 0) \
	MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD72065_MODIFY(_tag, _intrf) \
  MCFG_DEVICE_MODIFY(_tag)	      \
  MCFG_DEVICE_CONFIG(_intrf)

#define MCFG_UPD72065_REMOVE(_tag)		\
  MCFG_DEVICE_REMOVE(_tag)


#endif /* __UPD765_H__ */