~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/emu/machine/mc6852.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
 
3
 
    Motorola MC6852 Synchronous Serial Data Adapter emulation
4
 
 
5
 
    Copyright MESS Team.
6
 
    Visit http://mamedev.org for licensing and usage restrictions.
7
 
 
8
 
**********************************************************************/
9
 
 
10
 
/*
11
 
 
12
 
    TODO:
13
 
 
14
 
    - FIFO
15
 
    - receive
16
 
    - transmit
17
 
    - parity
18
 
    - 1-sync-character mode
19
 
    - 2-sync-character mode
20
 
    - external sync mode
21
 
    - interrupts
22
 
 
23
 
*/
24
 
 
25
 
#include "emu.h"
26
 
#include "mc6852.h"
27
 
#include "machine/devhelpr.h"
28
 
 
29
 
 
30
 
// device type definition
31
 
const device_type MC6852 = &device_creator<mc6852_device>;
32
 
 
33
 
 
34
 
//**************************************************************************
35
 
//  MACROS / CONSTANTS
36
 
//**************************************************************************
37
 
 
38
 
#define LOG 0
39
 
 
40
 
 
41
 
#define S_RDA                   0x01
42
 
#define S_TDRA                  0x02
43
 
#define S_DCD                   0x04
44
 
#define S_CTS                   0x08
45
 
#define S_TUF                   0x10
46
 
#define S_RX_OVRN               0x20
47
 
#define S_PE                    0x40
48
 
#define S_IRQ                   0x80
49
 
 
50
 
 
51
 
#define C1_RX_RS                0x01
52
 
#define C1_TX_RS                0x02
53
 
#define C1_STRIP_SYNC   0x04
54
 
#define C1_CLEAR_SYNC   0x08
55
 
#define C1_TIE                  0x10
56
 
#define C1_RIE                  0x20
57
 
#define C1_AC_MASK              0xc0
58
 
#define C1_AC_C2                0x00
59
 
#define C1_AC_C3                0x40
60
 
#define C1_AC_SYNC              0x80
61
 
#define C1_AC_TX_FIFO   0xc0
62
 
 
63
 
 
64
 
#define C2_PC1                  0x01
65
 
#define C2_PC2                  0x02
66
 
#define C2_1_2_BYTE             0x04
67
 
#define C2_WS_MASK              0x38
68
 
#define C2_WS_6_E               0x00
69
 
#define C2_WS_6_O               0x08
70
 
#define C2_WS_7                 0x10
71
 
#define C2_WS_8                 0x18
72
 
#define C2_WS_7_E               0x20
73
 
#define C2_WS_7_O               0x28
74
 
#define C2_WS_8_E               0x30
75
 
#define C2_WS_8_O               0x38
76
 
#define C2_TX_SYNC              0x40
77
 
#define C2_EIE                  0x80
78
 
 
79
 
 
80
 
#define C3_E_I_SYNC             0x01
81
 
#define C3_1_2_SYNC             0x02
82
 
#define C3_CLEAR_CTS    0x04
83
 
#define C3_CTUF                 0x08
84
 
 
85
 
 
86
 
//**************************************************************************
87
 
//  INLINE HELPERS
88
 
//**************************************************************************
89
 
 
90
 
inline void mc6852_device::receive()
91
 
{
92
 
}
93
 
 
94
 
inline void mc6852_device::transmit()
95
 
{
96
 
}
97
 
 
98
 
 
99
 
 
100
 
//**************************************************************************
101
 
//  LIVE DEVICE
102
 
//**************************************************************************
103
 
 
104
 
//-------------------------------------------------
105
 
//  mc6852_device - constructor
106
 
//-------------------------------------------------
107
 
 
108
 
mc6852_device::mc6852_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
109
 
    : device_t(mconfig, MC6852, "MC6852", tag, owner, clock)
110
 
{
111
 
}
112
 
 
113
 
 
114
 
//-------------------------------------------------
115
 
//  device_config_complete - perform any
116
 
//  operations now that the configuration is
117
 
//  complete
118
 
//-------------------------------------------------
119
 
 
120
 
void mc6852_device::device_config_complete()
121
 
{
122
 
        // inherit a copy of the static data
123
 
        const mc6852_interface *intf = reinterpret_cast<const mc6852_interface *>(static_config());
124
 
        if (intf != NULL)
125
 
                *static_cast<mc6852_interface *>(this) = *intf;
126
 
 
127
 
        // or initialize to defaults if none provided
128
 
        else
129
 
        {
130
 
                memset(&m_in_rx_data_cb, 0, sizeof(m_in_rx_data_cb));
131
 
                memset(&m_out_tx_data_cb, 0, sizeof(m_out_tx_data_cb));
132
 
                memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
133
 
                memset(&m_in_cts_cb, 0, sizeof(m_in_cts_cb));
134
 
                memset(&m_in_dcd_cb, 0, sizeof(m_in_dcd_cb));
135
 
                memset(&m_out_sm_dtr_cb, 0, sizeof(m_out_sm_dtr_cb));
136
 
                memset(&m_out_tuf_cb, 0, sizeof(m_out_tuf_cb));
137
 
        }
138
 
}
139
 
 
140
 
 
141
 
//-------------------------------------------------
142
 
//  device_start - device-specific startup
143
 
//-------------------------------------------------
144
 
 
145
 
void mc6852_device::device_start()
146
 
{
147
 
        // resolve callbacks
148
 
        m_in_rx_data_func.resolve(m_in_rx_data_cb, *this);
149
 
        m_out_tx_data_func.resolve(m_out_tx_data_cb, *this);
150
 
        m_out_irq_func.resolve(m_out_irq_cb, *this);
151
 
        m_in_cts_func.resolve(m_in_cts_cb, *this);
152
 
        m_in_dcd_func.resolve(m_in_dcd_cb, *this);
153
 
        m_out_sm_dtr_func.resolve(m_out_sm_dtr_cb, *this);
154
 
        m_out_tuf_func.resolve(m_out_tuf_cb, *this);
155
 
 
156
 
        if (m_rx_clock > 0)
157
 
        {
158
 
                m_rx_timer = timer_alloc(TIMER_RX);
159
 
                m_rx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_rx_clock));
160
 
        }
161
 
 
162
 
        if (m_tx_clock > 0)
163
 
        {
164
 
                m_tx_timer = timer_alloc(TIMER_TX);
165
 
                m_tx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_tx_clock));
166
 
        }
167
 
 
168
 
        // register for state saving
169
 
        save_item(NAME(m_status));
170
 
        save_item(NAME(m_cr));
171
 
        save_item(NAME(m_scr));
172
 
        save_item(NAME(m_rx_fifo));
173
 
        save_item(NAME(m_tx_fifo));
174
 
        save_item(NAME(m_tdr));
175
 
        save_item(NAME(m_tsr));
176
 
        save_item(NAME(m_rdr));
177
 
        save_item(NAME(m_rsr));
178
 
        save_item(NAME(m_cts));
179
 
        save_item(NAME(m_dcd));
180
 
        save_item(NAME(m_sm_dtr));
181
 
        save_item(NAME(m_tuf));
182
 
}
183
 
 
184
 
 
185
 
//-------------------------------------------------
186
 
//  device_reset - device-specific reset
187
 
//-------------------------------------------------
188
 
 
189
 
void mc6852_device::device_reset()
190
 
{
191
 
        /* set receiver shift register to all 1's */
192
 
        m_rsr = 0xff;
193
 
 
194
 
        /* reset and inhibit receiver/transmitter sections */
195
 
        m_cr[0] |= (C1_TX_RS | C1_RX_RS);
196
 
}
197
 
 
198
 
 
199
 
//-------------------------------------------------
200
 
//  device_timer - handler timer events
201
 
//-------------------------------------------------
202
 
 
203
 
void mc6852_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
204
 
{
205
 
        switch (id)
206
 
        {
207
 
        case TIMER_RX:
208
 
                receive();
209
 
                break;
210
 
 
211
 
        case TIMER_TX:
212
 
                transmit();
213
 
                break;
214
 
        }
215
 
}
216
 
 
217
 
 
218
 
//-------------------------------------------------
219
 
//  read -
220
 
//-------------------------------------------------
221
 
 
222
 
READ8_MEMBER( mc6852_device::read )
223
 
{
224
 
        UINT8 data = 0;
225
 
 
226
 
        if (BIT(offset, 0))
227
 
        {
228
 
                /* receive data FIFO */
229
 
        }
230
 
        else
231
 
        {
232
 
                /* status */
233
 
                data = m_status;
234
 
        }
235
 
 
236
 
        return data;
237
 
}
238
 
 
239
 
 
240
 
//-------------------------------------------------
241
 
//  write -
242
 
//-------------------------------------------------
243
 
 
244
 
WRITE8_MEMBER( mc6852_device::write )
245
 
{
246
 
        if (BIT(offset, 0))
247
 
        {
248
 
                switch (m_cr[0] & C1_AC_MASK)
249
 
                {
250
 
                case C1_AC_C2:
251
 
                        /* control 2 */
252
 
                        m_cr[1] = data;
253
 
                        break;
254
 
 
255
 
                case C1_AC_C3:
256
 
                        /* control 3 */
257
 
                        m_cr[2] = data;
258
 
                        break;
259
 
 
260
 
                case C1_AC_SYNC:
261
 
                        /* sync code */
262
 
                        m_scr = data;
263
 
                        break;
264
 
 
265
 
                case C1_AC_TX_FIFO:
266
 
                        /* transmit data FIFO */
267
 
                        break;
268
 
                }
269
 
        }
270
 
        else
271
 
        {
272
 
                /* receiver reset */
273
 
                if (data & C1_RX_RS)
274
 
                {
275
 
                        /* When Rx Rs is set, it clears the receiver
276
 
            control logic, sync logic, error logic, Rx Data FIFO Control,
277
 
            Parity Error status bit, and DCD interrupt. The Receiver Shift
278
 
            Register is set to ones.
279
 
            */
280
 
 
281
 
                        if (LOG) logerror("MC6852 '%s' Receiver Reset\n", tag());
282
 
 
283
 
                        m_status &= ~(S_RX_OVRN | S_PE | S_DCD | S_RDA);
284
 
                        m_rsr = 0xff;
285
 
                }
286
 
 
287
 
                /* transmitter reset */
288
 
                if (data & C1_TX_RS)
289
 
                {
290
 
                        /* When Tx Rs is set, it clears the transmitter
291
 
            control section, Transmitter Shift Register, Tx Data FIFO
292
 
            Control (the Tx Data FIFO can be reloaded after one E clock
293
 
            pulse), the Transmitter Underflow status bit, and the CTS interrupt,
294
 
            and inhibits the TDRA status bit (in the one-sync-character
295
 
            and two-sync-character modes).*/
296
 
 
297
 
                        if (LOG) logerror("MC6852 '%s' Transmitter Reset\n", tag());
298
 
 
299
 
                        m_status &= ~(S_TUF | S_CTS | S_TDRA);
300
 
                }
301
 
 
302
 
                if (LOG)
303
 
                {
304
 
                        if (data & C1_STRIP_SYNC) logerror("MC6852 '%s' Strip Synchronization Characters\n", tag());
305
 
                        if (data & C1_CLEAR_SYNC) logerror("MC6852 '%s' Clear Synchronization\n", tag());
306
 
                }
307
 
 
308
 
                m_cr[0] = data;
309
 
        }
310
 
}
311
 
 
312
 
 
313
 
//-------------------------------------------------
314
 
//  rx_clk_w -
315
 
//-------------------------------------------------
316
 
 
317
 
WRITE_LINE_MEMBER( mc6852_device::rx_clk_w )
318
 
{
319
 
        if (state) receive();
320
 
}
321
 
 
322
 
 
323
 
//-------------------------------------------------
324
 
//  tx_clk_w -
325
 
//-------------------------------------------------
326
 
 
327
 
WRITE_LINE_MEMBER( mc6852_device::tx_clk_w )
328
 
{
329
 
        if (state) transmit();
330
 
}
331
 
 
332
 
 
333
 
//-------------------------------------------------
334
 
//  cts_w -
335
 
//-------------------------------------------------
336
 
 
337
 
WRITE_LINE_MEMBER( mc6852_device::cts_w )
338
 
{
339
 
        m_cts = state;
340
 
}
341
 
 
342
 
 
343
 
//-------------------------------------------------
344
 
//  dcd_w -
345
 
//-------------------------------------------------
346
 
 
347
 
WRITE_LINE_MEMBER( mc6852_device::dcd_w )
348
 
{
349
 
        m_dcd = state;
350
 
}
351
 
 
352
 
 
353
 
//-------------------------------------------------
354
 
//  sm_dtr_r -
355
 
//-------------------------------------------------
356
 
 
357
 
READ_LINE_MEMBER( mc6852_device::sm_dtr_r )
358
 
{
359
 
        return m_sm_dtr;
360
 
}
361
 
 
362
 
 
363
 
//-------------------------------------------------
364
 
//  tuf_r -
365
 
//-------------------------------------------------
366
 
 
367
 
READ_LINE_MEMBER( mc6852_device::tuf_r )
368
 
{
369
 
        return m_tuf;
370
 
}