summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/ieee488/c8050.h
blob: 2c44c6dc0e3697c1663894ab674c862c6d604b2f (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Commodore 8050/8250/SFD-1001 Disk Drive emulation

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

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

#pragma once

#ifndef __C8050__
#define __C8050__

#include "emu.h"
#include "ieee488.h"
#include "cpu/m6502/m6502.h"
#include "cpu/m6502/m6504.h"
#include "imagedev/flopdrv.h"
#include "formats/d64_dsk.h"
#include "formats/g64_dsk.h"
#include "machine/6522via.h"
#include "machine/6532riot.h"
#include "machine/mos6530.h"



//**************************************************************************
//  MACROS / CONSTANTS
//**************************************************************************

#define G64_BUFFER_SIZE         32768
#define G64_SYNC_MARK           0x3ff


const int C8050_BITRATE[] =
{
	XTAL_12MHz/2/16,    /* tracks  1-39 */
	XTAL_12MHz/2/15,    /* tracks 40-53 */
	XTAL_12MHz/2/14,    /* tracks 54-65 */
	XTAL_12MHz/2/13     /* tracks 65-84 */
};



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

// ======================> c8050_device

class c8050_device :  public device_t,
						public device_ieee488_interface
{
public:
	// construction/destruction
	c8050_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, bool double_sided, const char *shortname, const char *source);
	c8050_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// optional information overrides
	virtual const rom_entry *device_rom_region() const;
	virtual machine_config_constructor device_mconfig_additions() const;
	virtual ioport_constructor device_input_ports() const;

	// not really public
	static void on_disk0_change(device_image_interface &image);
	static void on_disk1_change(device_image_interface &image);

	DECLARE_READ8_MEMBER( dio_r );
	DECLARE_WRITE8_MEMBER( dio_w );
	DECLARE_READ8_MEMBER( riot1_pa_r );
	DECLARE_WRITE8_MEMBER( riot1_pa_w );
	DECLARE_READ8_MEMBER( riot1_pb_r );
	DECLARE_WRITE8_MEMBER( riot1_pb_w );
	DECLARE_READ8_MEMBER( via_pa_r );
	DECLARE_READ8_MEMBER( via_pb_r );
	DECLARE_WRITE8_MEMBER( via_pb_w );
	DECLARE_WRITE_LINE_MEMBER( mode_sel_w );
	DECLARE_WRITE_LINE_MEMBER( rw_sel_w );
	DECLARE_READ8_MEMBER( pi_r );
	DECLARE_WRITE8_MEMBER( pi_w );
	DECLARE_READ8_MEMBER( miot_pb_r );
	DECLARE_WRITE8_MEMBER( miot_pb_w );

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

	// device_ieee488_interface overrides
	virtual void ieee488_atn(int state);
	virtual void ieee488_ifc(int state);

	inline void byte_ready(int state);
	inline void update_ieee_signals();
	inline void update_gcr_data();
	inline void read_current_track(int unit);
	inline void spindle_motor(int unit, int mtr);
	inline void micropolis_step_motor(int unit, int stp);
	inline void mpi_step_motor(int unit, int stp);

	required_device<m6502_device> m_maincpu;
	required_device<m6504_device> m_fdccpu;
	required_device<riot6532_device> m_riot0;
	required_device<riot6532_device> m_riot1;
	required_device<mos6530_device> m_miot;
	required_device<via6522_device> m_via;
	required_device<legacy_floppy_image_device> m_image0;
	optional_device<legacy_floppy_image_device> m_image1;
	required_memory_region m_gcr;
	required_ioport m_address;

	struct {
		// motors
		int m_stp;                              // stepper motor phase
		int m_mtr;                              // spindle motor on

		// track
		UINT8 m_track_buffer[G64_BUFFER_SIZE];  // track data buffer
		int m_track_len;                        // track length
		int m_buffer_pos;                       // byte position within track buffer
		int m_bit_pos;                          // bit position within track buffer byte

		// devices
		device_t *m_image;
	} m_unit[2];

	int m_drive;                        // selected drive
	int m_side;                         // selected side
	bool m_double_sided;

	// IEEE-488 bus
	int m_rfdo;                         // not ready for data output
	int m_daco;                         // not data accepted output
	int m_atna;                         // attention acknowledge
	int m_ifc;

	// track
	int m_ds;                           // density select
	int m_bit_count;                    // GCR bit counter
	UINT16 m_sr;                        // GCR data shift register
	UINT8 m_pi;                         // parallel data input
	UINT16 m_i;                         // GCR encoder/decoded ROM address
	UINT8 m_e;                          // GCR encoder/decoded ROM data

	// signals
	int m_ready;                        // byte ready
	int m_mode;                         // mode select
	int m_rw;                           // read/write select
	int m_miot_irq;                     // MIOT interrupt

	// timers
	emu_timer *m_bit_timer;
};


// ======================> c8250_device

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

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


// ======================> c8250lp_device

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

	// optional information overrides
	virtual const rom_entry *device_rom_region() const;
	virtual machine_config_constructor device_mconfig_additions() const;
};


// ======================> sfd1001_device

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

	// optional information overrides
	virtual const rom_entry *device_rom_region() const;
	virtual machine_config_constructor device_mconfig_additions() const;
};


// device type definition
extern const device_type C8050;
extern const device_type C8250;
extern const device_type C8250LP;
extern const device_type SFD1001;



#endif