Previous 15994 Revisions Next

r3482 Thursday 23rd October, 2008 at 14:55:47 UTC by Curt Coder
[Z80DART] Rewritten for bit accuracy, work in progress.
[ABC802] Fixed memory banking.
[src/mess/drivers]abc80x.c
[src/mess/includes]abc80x.h
[src/mess/machine]mtx.c z80dart.c z80dart.h
[src/mess/video]abc800.c abc802.c abc806.c

src/mess/video/abc800.c
r3481r3482
9797{
9898   abc800_state *state = device->machine->driver_data;
9999 
100   z80dart_set_ri(state->z80dart, 1, vsync);
100   z80dart_ri_w(state->z80dart, 1, vsync);
101101}
102102 
103103static MC6845_UPDATE_ROW( abc800c_update_row )
src/mess/video/abc802.c
r3481r3482
119119#include "machine/z80dart.h"
120120#include "video/mc6845.h"
121121 
122/* Character Memory */
123 
124READ8_HANDLER( abc802_charram_r )
125{
126   abc802_state *state = machine->driver_data;
127 
128   return state->charram[offset];
129}
130 
131WRITE8_HANDLER( abc802_charram_w )
132{
133   abc802_state *state = machine->driver_data;
134 
135   state->charram[offset] = data;
136}
137 
122138/* MC6845 Row Update */
123139 
124140static MC6845_UPDATE_ROW( abc802_update_row )
r3481r3482
131147   {
132148      int bit;
133149 
134      UINT8 code = videoram[(ma + column) & 0x7ff];
150      UINT8 code = state->charram[(ma + column) & 0x7ff];
135151      UINT16 address = ((code & 0x80) << 5) | ((code & 0x7f) << 4);
136152      UINT8 ra_latch = ra;
137153      UINT8 data;
r3481r3482
220236   if (!vsync)
221237   {
222238      /* flash clock */
223      if (state->flshclk_ctr == 31)
239      if (state->flshclk_ctr & 0x20)
224240      {
225         state->flshclk = 1;
241         state->flshclk = !state->flshclk;
226242         state->flshclk_ctr = 0;
227243      }
228244      else
229245      {
230         state->flshclk = 0;
231246         state->flshclk_ctr++;
232247      }
233248   }
234249 
235250   /* signal _DEW to DART */
236   z80dart_set_ri(state->z80dart, 1, !vsync);
251   z80dart_ri_w(state->z80dart, 1, !vsync);
237252}
238253 
239254/* MC6845 Interfaces */
r3481r3482
255270static VIDEO_START( abc802 )
256271{
257272   abc802_state *state = machine->driver_data;
273   
274   /* allocate memory */
258275 
276   state->charram = auto_malloc(ABC802_CHAR_RAM_SIZE);
277 
259278   /* find devices */
260279 
261280   state->mc6845 = devtag_get_device(machine, MC6845, MC6845_TAG);
r3481r3482
266285 
267286   /* register for state saving */
268287 
288   state_save_register_global_pointer(state->charram, ABC802_CHAR_RAM_SIZE);
289 
269290   state_save_register_global(state->flshclk_ctr);
270291   state_save_register_global(state->flshclk);
271292   state_save_register_global(state->mux80_40);
src/mess/video/abc806.c
r3481r3482
359359      else if (state->d_vsync && !vsync)
360360      {
361361         /* flash clock */
362         if (state->flshclk_ctr == 31)
362         if (state->flshclk_ctr & 0x20)
363363         {
364            state->flshclk = 1;
364            state->flshclk = !state->flshclk;
365365            state->flshclk_ctr = 0;
366366         }
367367         else
368368         {
369            state->flshclk = 0;
370369            state->flshclk_ctr++;
371370         }
372371      }
r3481r3482
374373      if (state->d_vsync != vsync)
375374      {
376375         /* signal _DEW to DART */
377         z80dart_set_ri(state->z80dart, 1, !vsync);
376         z80dart_ri_w(state->z80dart, 1, !vsync);
378377      }
379378
380379      state->d_vsync = vsync;
src/mess/includes/abc80x.h
r3481r3482
1616#define ABC802_ATE   0x80
1717#define ABC802_INV   0x80
1818
19#define ABC802_CHAR_RAM_SIZE   0x800
1920#define ABC806_CHAR_RAM_SIZE   0x800
2021#define ABC806_ATTR_RAM_SIZE   0x800
2122#define ABC806_VIDEO_RAM_SIZE   0x20000
r3481r3482
5152typedef struct _abc802_state abc802_state;
5253struct _abc802_state
5354{
55   /* cpu state */
56   int lrs;            /* low RAM select */
57
5458   /* keyboard state */
5559   int abc77_txd;         /* ABC-77 transmit data */
5660
5761   /* video state */
62   UINT8 *charram;         /* character RAM */
63
5864   int flshclk_ctr;      /* flash clock counter */
5965   int flshclk;         /* flash clock */
6066   int mux80_40;         /* 40/80 column mode */
r3481r3482
128134
129135/*----------- defined in video/abc802.c -----------*/
130136
137READ8_HANDLER( abc802_charram_r );
138WRITE8_HANDLER( abc802_charram_w );
139
131140MACHINE_DRIVER_EXTERN(abc802_video);
132141
133142/*----------- defined in video/abc806.c -----------*/
src/mess/machine/z80dart.c
r3481r3482
11/***************************************************************************
22
3    Z80 DART (Z8470) implementation
3    Z80 DART Dual Asynchronous Receiver/Transmitter emulation
44
5    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
5    Copyright (c) 2008, The MESS Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
88***************************************************************************/
99
10/*
11
12   TODO:
13
14   - save state support
15   - break detection
16   - wr0 reset tx interrupt pending
17   - wait/ready
18   - 1.5 stop bits
19
20*/
21
1022#include "driver.h"
1123#include "z80dart.h"
1224#include "cpu/z80/z80.h"
1325#include "cpu/z80/z80daisy.h"
1426
15
16
1727/***************************************************************************
1828    DEBUGGING
1929***************************************************************************/
2030
21#define VERBOSE      1
31#define VERBOSE 1
2232
23#define VPRINTF(x) do { if (VERBOSE) logerror x; } while (0)
33#define LOGERROR if (VERBOSE) logerror
2434
25
26
2735/***************************************************************************
2836    CONSTANTS
2937***************************************************************************/
3038
31/* interrupt states */
32#define INT_CHB_TRANSMIT   0x00      /* not confirmed */
33#define INT_CHB_STATUS      0x01
34#define INT_CHB_RECEIVE      0x02
35#define INT_CHB_ERROR      0x03
39enum
40{
41   STATE_START = 0,
42   STATE_DATA,
43   STATE_PARITY,
44   STATE_STOP,
45   STATE_STOP2
46};
3647
37#define INT_CHA_TRANSMIT   0x04      /* not confirmed */
38#define INT_CHA_STATUS      0x05
39#define INT_CHA_RECEIVE      0x06
40#define INT_CHA_ERROR      0x07
48enum
49{
50   INT_TRANSMIT = 0,
51   INT_EXTERNAL,
52   INT_RECEIVE,
53   INT_SPECIAL
54};
4155
42/* DART write register 0 */
43#define DART_WR0_RESET_MASK               0xc0   /* D7-D6: Reset control */
44#define DART_WR0_RESET_NULL               0x00   /*  00 = NULL code */
45#define DART_WR0_RESET_RX_CRC            0x40   /*  01 = Reset Rx CRC checker */
46#define DART_WR0_RESET_TX_CRC            0x80   /*  10 = Reset Tx CRC generator */
47#define DART_WR0_RESET_TX_LATCH            0xc0   /*  11 = Reset Tx Underrun/EOM latch */
48#define DART_WR0_COMMAND_MASK            0x38   /* D5-D3: Command */
49#define DART_WR0_COMMAND_NULL            0x00   /*  000 = NULL code */
50                                       /*  001 = not used */
51#define DART_WR0_COMMAND_RES_STATUS_INT      0x10   /*  010 = reset ext/status interrupts */
52#define DART_WR0_COMMAND_CH_RESET         0x18   /*  011 = Channel reset */
53#define DART_WR0_COMMAND_ENA_RX_INT         0x20   /*  100 = Enable int on next Rx character */
54#define DART_WR0_COMMAND_RES_TX_INT         0x28   /*  101 = Reset Tx int pending */
55#define DART_WR0_COMMAND_RES_ERROR         0x30   /*  110 = Error reset */
56#define DART_WR0_COMMAND_RETI            0x38   /*  111 = Return from int (CH-A only) */
57#define DART_WR0_REGISTER_MASK            0x07   /* D2-D0: Register select (0-7) */
56#define Z80DART_RR0_RX_CHAR_AVAILABLE   0x01
57#define Z80DART_RR0_INTERRUPT_PENDING   0x02
58#define Z80DART_RR0_TX_BUFFER_EMPTY      0x04
59#define Z80DART_RR0_DCD               0x08
60#define Z80DART_RR0_RI               0x10
61#define Z80DART_RR0_CTS               0x20
62#define Z80DART_RR0_BREAK            0x80 /* not supported */
5863
59/* DART write register 1 */
60#define DART_WR1_READY_WAIT_ENA            0x80   /* D7 = READY/WAIT enable */
61#define DART_WR1_READY_WAIT_FUNCTION      0x40   /* D6 = READY/WAIT function */
62#define DART_WR1_READY_WAIT_ON_RT         0x20   /* D5 = READY/WAIT on R/T */
63#define DART_WR1_RXINT_MASK               0x18   /* D4-D3 = Rx int control */
64#define DART_WR1_RXINT_DISABLE            0x00   /*  00 = Rx int disable */
65#define DART_WR1_RXINT_FIRST            0x08   /*  01 = Rx int on first character */
66#define DART_WR1_RXINT_ALL_PARITY         0x10   /*  10 = int on all Rx characters (parity affects vector) */
67#define DART_WR1_RXINT_ALL_NOPARITY         0x18   /*  11 = int on all Rx characters (parity ignored) */
68#define DART_WR1_STATUS_AFFECTS_VECTOR      0x04   /* D2 = Status affects vector (CH-B only) */
69#define DART_WR1_TXINT_ENABLE            0x02   /* D1 = Tx int enable */
70#define DART_WR1_STATUSINT_ENABLE         0x01   /* D0 = Ext int enable */
64#define Z80DART_RR1_ALL_SENT         0x01
65#define Z80DART_RR1_PARITY_ERROR      0x10
66#define Z80DART_RR1_RX_OVERRUN_ERROR   0x20
67#define Z80DART_RR1_FRAMING_ERROR      0x40
7168
72/* DART write register 2 (CH-B only) */
73#define DART_WR2_INT_VECTOR_MASK         0xff   /* D7-D0 = interrupt vector */
69#define Z80DART_WR0_REGISTER_MASK      0x07
70#define Z80DART_WR0_COMMAND_MASK      0x38
71#define Z80DART_WR0_NULL_CODE         0x00
72#define Z80DART_WR0_RESET_EXT_STATUS   0x10
73#define Z80DART_WR0_CHANNEL_RESET      0x18
74#define Z80DART_WR0_ENABLE_INT_NEXT_RX   0x20
75#define Z80DART_WR0_RESET_TX_INT      0x28 /* not supported */
76#define Z80DART_WR0_ERROR_RESET         0x30
77#define Z80DART_WR0_RETURN_FROM_INT      0x38 /* not supported */
7478
75/* DART write register 3 */
76#define DART_WR3_RX_DATABITS_MASK         0xc0   /* D7-D6 = Rx Data bits */
77#define DART_WR3_RX_DATABITS_5            0x00   /*  00 = Rx 5 bits/character */
78#define DART_WR3_RX_DATABITS_7            0x40   /*  01 = Rx 7 bits/character */
79#define DART_WR3_RX_DATABITS_6            0x80   /*  10 = Rx 6 bits/character */
80#define DART_WR3_RX_DATABITS_8            0xc0   /*  11 = Rx 8 bits/character */
81#define DART_WR3_AUTO_ENABLES            0x20   /* D5 = Auto enables */
82                                       /* D1-D4 = not used */
83#define DART_WR3_RX_ENABLE               0x01   /* D0 = Rx enable */
79#define Z80DART_WR1_EXT_INT_ENABLE      0x01
80#define Z80DART_WR1_TX_INT_ENABLE      0x02
81#define Z80DART_WR1_STATUS_VECTOR      0x04
82#define Z80DART_WR1_RX_INT_ENABLE_MASK   0x18
83#define Z80DART_WR1_RX_INT_DISABLE      0x00
84#define Z80DART_WR1_RX_INT_FIRST      0x08
85#define Z80DART_WR1_RX_INT_ALL_PARITY   0x10 /* not supported */
86#define Z80DART_WR1_RX_INT_ALL         0x18
87#define Z80DART_WR1_WRDY_ON_RX_TX      0x20 /* not supported */
88#define Z80DART_WR1_WRDY_FUNCTION      0x40 /* not supported */
89#define Z80DART_WR1_WRDY_ENABLE         0x80 /* not supported */
8490
85/* DART write register 4 */
86#define DART_WR4_CLOCK_MODE_MASK         0xc0   /* D7-D6 = Clock mode */
87#define DART_WR4_CLOCK_MODE_x1            0x00   /*  00 = x1 clock mode */
88#define DART_WR4_CLOCK_MODE_x16            0x40   /*  01 = x16 clock mode */
89#define DART_WR4_CLOCK_MODE_x32            0x80   /*  10 = x32 clock mode */
90#define DART_WR4_CLOCK_MODE_x64            0xc0   /*  11 = x64 clock mode */
91                                       /* D5-D4 = not used */
92#define DART_WR4_STOPBITS_MASK            0x0c   /* D3-D2 = Stop bits */
93                                       /*  00 = not used */
94#define DART_WR4_STOPBITS_1               0x04   /*  01 = 1 stop bit/character */
95#define DART_WR4_STOPBITS_15            0x08   /*  10 = 1.5 stop bits/character */
96#define DART_WR4_STOPBITS_2               0x0c   /*  11 = 2 stop bits/character */
97#define DART_WR4_PARITY_EVEN            0x02   /* D1 = Parity even/odd */
98#define DART_WR4_PARITY_ENABLE            0x01   /* D0 = Parity enable */
91#define Z80DART_WR3_RX_ENABLE         0x01
92#define Z80DART_WR3_AUTO_ENABLES      0x20
93#define Z80DART_WR3_RX_WORD_LENGTH_MASK   0xc0
94#define Z80DART_WR3_RX_WORD_LENGTH_5   0x00
95#define Z80DART_WR3_RX_WORD_LENGTH_7   0x40
96#define Z80DART_WR3_RX_WORD_LENGTH_6   0x80
97#define Z80DART_WR3_RX_WORD_LENGTH_8   0xc0
9998
100/* DART write register 5 */
101#define DART_WR5_DTR                  0x80   /* D7 = DTR */
102#define DART_WR5_TX_DATABITS_MASK         0x60   /* D6-D5 = Tx Data bits */
103#define DART_WR5_TX_DATABITS_5            0x00   /*  00 = Tx 5 bits/character */
104#define DART_WR5_TX_DATABITS_7            0x20   /*  01 = Tx 7 bits/character */
105#define DART_WR5_TX_DATABITS_6            0x40   /*  10 = Tx 6 bits/character */
106#define DART_WR5_TX_DATABITS_8            0x60   /*  11 = Tx 8 bits/character */
107#define DART_WR5_SEND_BREAK               0x10   /* D4 = Send break */
108#define DART_WR5_TX_ENABLE               0x08   /* D3 = Tx Enable */
109                                       /* D2 = not used */
110#define DART_WR5_RTS                  0x02   /* D1 = RTS */
111                                       /* D0 = not used */
99#define Z80DART_WR4_PARITY_ENABLE      0x01 /* not supported */
100#define Z80DART_WR4_PARITY_EVEN         0x02 /* not supported */
101#define Z80DART_WR4_STOP_BITS_MASK      0x0c
102#define Z80DART_WR4_STOP_BITS_1         0x04
103#define Z80DART_WR4_STOP_BITS_1_5      0x08 /* not supported */
104#define Z80DART_WR4_STOP_BITS_2         0x0c
105#define Z80DART_WR4_CLOCK_MODE_MASK      0xc0
106#define Z80DART_WR4_CLOCK_MODE_X1      0x00
107#define Z80DART_WR4_CLOCK_MODE_X16      0x40
108#define Z80DART_WR4_CLOCK_MODE_X32      0x80
109#define Z80DART_WR4_CLOCK_MODE_X64      0xc0
112110
113/* DART read register 0 */
114#define DART_RR0_BREAK_ABORT            0x80   /* D7 = Break/abort */
115                                       /* D6 = not used */
116#define DART_RR0_CTS                  0x20   /* D5 = CTS */
117#define DART_RR0_RI                     0x10   /* D4 = RI */
118#define DART_RR0_DCD                  0x08   /* D3 = DCD */
119#define DART_RR0_TX_BUFFER_EMPTY         0x04   /* D2 = Tx buffer empty */
120#define DART_RR0_INT_PENDING            0x02   /* D1 = int pending (CH-A only) */
121#define DART_RR0_RX_CHAR_AVAILABLE         0x01   /* D0 = Rx character available */
111#define Z80DART_WR5_RTS               0x02
112#define Z80DART_WR5_TX_ENABLE         0x08
113#define Z80DART_WR5_SEND_BREAK         0x10
114#define Z80DART_WR5_TX_WORD_LENGTH_MASK   0x60
115#define Z80DART_WR5_TX_WORD_LENGTH_5   0x00
116#define Z80DART_WR5_TX_WORD_LENGTH_7   0x40
117#define Z80DART_WR5_TX_WORD_LENGTH_6   0x80
118#define Z80DART_WR5_TX_WORD_LENGTH_8   0xc0
119#define Z80DART_WR5_DTR               0x80
122120
123/* DART read register 1 */
124                                       /* D7 = not used */
125#define DART_RR1_CRC_FRAMING_ERROR         0x40   /* D6 = Framing error */
126#define DART_RR1_RX_OVERRUN_ERROR         0x20   /* D5 = Rx overrun error */
127#define DART_RR1_PARITY_ERROR            0x10   /* D4 = Parity error */
128                                       /* D3-D1 = not used */
129#define DART_RR1_ALL_SENT               0x01   /* D0 = All sent */
130
131/* DART read register 2 (CH-B only) */
132#define DART_RR2_VECTOR_MASK            0xff   /* D7-D0 = Interrupt vector */
133
134
135
136121/***************************************************************************
137122    TYPE DEFINITIONS
138123***************************************************************************/
r3481r3482
140125typedef struct _dart_channel dart_channel;
141126struct _dart_channel
142127{
143   UINT8      regs[6];         /* 6 writeable registers */
144   UINT8      status[4];         /* 3 readable registers */
145   int         inbuf;            /* input buffer */
146   int         outbuf;            /* output buffer */
147   UINT8      int_on_next_rx;      /* interrupt on next rx? */
148   emu_timer *receive_timer;      /* timer to clock data in */
149   UINT8      receive_buffer[16];   /* buffer for incoming data */
150   UINT8      receive_inptr;      /* index of data coming in */
151   UINT8      receive_outptr;      /* index of data going out */
152};
128   /* register state */
129   UINT8 rr[3];         /* read register */
130   UINT8 wr[6];         /* write register */
153131
132   /* receiver state */
133   UINT8 rx_data_fifo[3];   /* receive data FIFO */
134   UINT8 rx_error_fifo[3];   /* receive error FIFO */
135   UINT8 rx_shift;         /* 8-bit receive shift register */
136   UINT8 rx_error;         /* current receive error */
137   int rx_fifo;         /* receive FIFO pointer */
154138
155typedef struct _z80dart z80dart;
156struct _z80dart
157{
158   dart_channel   chan[2];         /* 2 channels */
159   UINT8      int_state[8];      /* interrupt states */
139   int rx_clock;         /* receive clock pulse count */
140   int rx_state;         /* receive state */
141   int rx_bits;         /* bits received */
142   int rx_first;         /* first character received */
143   int rx_parity;         /* received data parity */
144   int rx_break;         /* receive break condition */
160145
161   void (*irq_cb)(const device_config *device, int state);
162   write8_device_func dtr_changed_cb;
163   write8_device_func rts_changed_cb;
164   write8_device_func break_changed_cb;
165   write8_device_func transmit_cb;
166   int (*receive_poll_cb)(const device_config *device, int ch);
146   int ri;               /* ring indicator latch */
147   int cts;            /* clear to send latch */
148   int dcd;            /* data carrier detect latch */
149
150   /* transmitter state */
151   UINT8 tx_data;         /* transmit data register */
152   UINT8 tx_shift;         /* transmit shift register */
153
154   int tx_clock;         /* transmit clock pulse count */
155   int tx_state;         /* transmit state */
156   int tx_bits;         /* bits transmitted */
157   int tx_parity;         /* transmitted data parity */
158
159   int dtr;            /* data terminal ready */
160   int rts;            /* request to send */
167161};
168162
163typedef struct _z80dart_t z80dart_t;
164struct _z80dart_t
165{
166   const z80dart_interface *intf;   /* interface */
169167
168   dart_channel channel[2];      /* channels */
170169
170   int clock;                  /* base clock */
171   int int_state[8];            /* interrupt state */
172
173   /* timers */
174   emu_timer *rxca_timer;
175   emu_timer *txca_timer;
176   emu_timer *rxtxcb_timer;
177};
178
171179/***************************************************************************
172180    FUNCTION PROTOTYPES
173181***************************************************************************/
174182
175static TIMER_CALLBACK(serial_callback);
176183static int z80dart_irq_state(const device_config *device);
184static void z80dart_irq_reti(const device_config *device);
177185
186/***************************************************************************
187    INLINE FUNCTIONS
188***************************************************************************/
178189
190INLINE z80dart_t *get_safe_token(const device_config *device)
191{
192   assert(device != NULL);
193   assert(device->token != NULL);
194   assert(device->type == Z80DART);
195   
196   return (z80dart_t *)device->token;
197}
179198
180/*
199/***************************************************************************
200    CALLBACK INTERFACE MANAGEMENT
201***************************************************************************/
181202
182    Interrupt priorities:
183        Ch A receive
184        Ch A transmit
185        Ch A external/status
186        Ch B receive
187        Ch B transmit
188        Ch B external/status
203static int z80dart_rxd_r(const device_config *device, int channel)
204{
205   z80dart_t *z80dart = get_safe_token(device);
189206
207   int data = 1;
190208
191    Initial configuration (both channels):
192        005D:dart_reg_w(0,4) = 44
193                    01 = x16 clock mode
194                    00 = 8 bit sync character
195                    01 = 1 stop bit/character
196                    Parity odd
197                    Parity disabled
209   if (z80dart->intf->rxd_r)
210   {
211      data = z80dart->intf->rxd_r(device, channel);
212   }
198213
199        005D:dart_reg_w(0,3) = C1
200                    11 = Rx 8 bits/character
201                    No auto enables
202                    No enter hunt phase
203                    No Rx CRC enable
204                    No address search mode
205                    No sync character load inhibit
206                    Rx enable
214   return data;
215}
207216
208        005D:dart_reg_w(0,5) = 68
209                    DTR = 0
210                    11 = Tx 8 bits/character
211                    No send break
212                    Tx enable
213                    SDLC
214                    No RTS
215                    No CRC enable
217static void z80dart_txd_w(const device_config *device, int channel, int state)
218{
219   z80dart_t *z80dart = get_safe_token(device);
216220
217        005D:dart_reg_w(0,2) = 40
218                    Vector = 0x40
221   if (z80dart->intf->on_txd_changed)
222   {
223      z80dart->intf->on_txd_changed(device, channel, state);
224   }
225}
219226
220        005D:dart_reg_w(0,1) = 1D
221                    No READY/WAIT
222                    No READY/WAIT function
223                    No READY/WAIT on R/T
224                    11 = int on all Rx characters (parity ignored)
225                    Status affects vector
226                    No Tx int enable
227                    Ext int enable
227static void z80dart_rts_w(const device_config *device, int channel, int state)
228{
229   z80dart_t *z80dart = get_safe_token(device);
228230
229*/
231   if (z80dart->intf->on_rts_changed)
232   {
233      z80dart->intf->on_rts_changed(device, channel, state);
234   }
230235
236   LOGERROR("Z80DART \"%s\" Channel %c : RTS %u\n", device->tag, 'A' + channel, state);
237}
231238
239static void z80dart_dtr_w(const device_config *device, int channel, int state)
240{
241   z80dart_t *z80dart = get_safe_token(device);
242
243   if (z80dart->intf->on_dtr_changed)
244   {
245      z80dart->intf->on_dtr_changed(device, channel, state);
246   }
247
248   LOGERROR("Z80DART \"%s\" Channel %c : DTR %u\n", device->tag, 'A' + channel, state);
249}
250
232251/***************************************************************************
233    INLINE FUNCTIONS
252    INTERNAL STATE MANAGEMENT
234253***************************************************************************/
235254
236INLINE z80dart *get_safe_token(const device_config *device)
255static void z80dart_check_interrupt(const device_config *device)
237256{
238   assert(device != NULL);
239   assert(device->token != NULL);
240   assert(device->type == Z80DART);
241   return (z80dart *)device->token;
257   z80dart_t *z80dart = get_safe_token(device);
258   int state = (z80dart_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE;
259
260   if (z80dart->intf->on_int_changed)
261   {
262      z80dart->intf->on_int_changed(device, state);
263   }
242264}
243265
266static void z80dart_trigger_interrupt(const device_config *device, int channel, int level)
267{
268   z80dart_t *z80dart = get_safe_token(device);
269   dart_channel *ch = &z80dart->channel[channel];
270   UINT8 vector = ch->wr[2];
271   int priority = (channel << 2) | level;
244272
245INLINE void interrupt_check(const device_config *device)
273   LOGERROR("Z80DART \"%s\" Channel %c : Interrupt Request %u\n", device->tag, 'A' + channel, level);
274
275   if ((channel == Z80DART_CH_B) && (ch->wr[1] & Z80DART_WR1_STATUS_VECTOR))
276   {
277      /* status affects vector */
278      vector = (ch->wr[2] & 0xf1) | (!channel << 3) | (level << 1);
279   }
280
281   /* update vector register */
282   ch->rr[2] = vector;
283
284   /* trigger interrupt */
285   z80dart->int_state[priority] |= Z80_DAISY_INT;
286   z80dart->channel[Z80DART_CH_A].rr[0] |= Z80DART_RR0_INTERRUPT_PENDING;
287
288   /* check for interrupt */
289   z80dart_check_interrupt(device);
290}
291
292static int z80dart_get_clock_mode(const device_config *device, int channel)
246293{
247   z80dart *dart = get_safe_token( device );
294   z80dart_t *z80dart = get_safe_token(device);
295   dart_channel *ch = &z80dart->channel[channel];
248296
249   /* if we have a callback, update it with the current state */
250   if (dart->irq_cb != NULL)
251      dart->irq_cb(device, (z80dart_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
297   int clocks = 1;
298
299   switch (ch->wr[4] & Z80DART_WR4_CLOCK_MODE_MASK)
300   {
301   case Z80DART_WR4_CLOCK_MODE_X1:
302      clocks = 1;
303
304   case Z80DART_WR4_CLOCK_MODE_X16:
305      clocks = 16;
306
307   case Z80DART_WR4_CLOCK_MODE_X32:
308      clocks = 32;
309
310   case Z80DART_WR4_CLOCK_MODE_X64:
311      clocks = 64;
312   }
313
314   return clocks;
252315}
253316
317static float z80dart_get_stop_bits(const device_config *device, int channel)
318{
319   z80dart_t *z80dart = get_safe_token(device);
320   dart_channel *ch = &z80dart->channel[channel];
254321
255INLINE attotime compute_time_per_character(const device_config *device, int ch)
256{
257   /* fix me -- should compute properly and include data, stop, parity bits */
258   return ATTOTIME_IN_HZ(9600 / 10);
322   float bits = 1;
323
324   switch (ch->wr[4] & Z80DART_WR4_STOP_BITS_MASK)
325   {
326   case Z80DART_WR4_STOP_BITS_1:
327      bits = 1;
328
329   case Z80DART_WR4_STOP_BITS_1_5:
330      bits = 1.5;
331
332   case Z80DART_WR4_STOP_BITS_2:
333      bits = 2;
334   }
335
336   return bits;
259337}
260338
261
262INLINE void reset_channel(const device_config *device, int ch)
339static int z80dart_get_rx_word_length(const device_config *device, int channel)
263340{
264   z80dart *dart = get_safe_token( device );
265   attotime tpc = compute_time_per_character(device, ch);
266   dart_channel *chan = &dart->chan[ch];
341   z80dart_t *z80dart = get_safe_token(device);
342   dart_channel *ch = &z80dart->channel[channel];
267343
268   chan->status[0] = DART_RR0_TX_BUFFER_EMPTY;
269   chan->status[1] = 0x00;
270   chan->status[2] = 0x00;
271   chan->int_on_next_rx = 0;
272   chan->outbuf = -1;
344   int bits = 5;
273345
274   dart->int_state[0 + 4*ch] = 0;
275   dart->int_state[1 + 4*ch] = 0;
276   dart->int_state[2 + 4*ch] = 0;
277   dart->int_state[3 + 4*ch] = 0;
346   switch (ch->wr[3] & Z80DART_WR3_RX_WORD_LENGTH_MASK)
347   {
348   case Z80DART_WR3_RX_WORD_LENGTH_5:
349      bits = 5;
278350
279   /* start the receive timer running */
280   timer_adjust_periodic(chan->receive_timer, tpc, ch, tpc);
351   case Z80DART_WR3_RX_WORD_LENGTH_6:
352      bits = 6;
353
354   case Z80DART_WR3_RX_WORD_LENGTH_7:
355      bits = 7;
356
357   case Z80DART_WR3_RX_WORD_LENGTH_8:
358      bits = 8;
359   }
360
361   return bits;
281362}
282363
364static int z80dart_get_tx_word_length(const device_config *device, int channel)
365{
366   z80dart_t *z80dart = get_safe_token(device);
367   dart_channel *ch = &z80dart->channel[channel];
283368
369   int bits = 5;
284370
285/***************************************************************************
286    CONTROL REGISTER READ/WRITE
287***************************************************************************/
371   switch (ch->wr[5] & Z80DART_WR5_TX_WORD_LENGTH_MASK)
372   {
373   case Z80DART_WR5_TX_WORD_LENGTH_5:
374      bits = 5;
288375
289/*-------------------------------------------------
290    z80dart_c_w - write to a control register
291-------------------------------------------------*/
376   case Z80DART_WR5_TX_WORD_LENGTH_6:
377      bits = 6;
292378
293WRITE8_DEVICE_HANDLER( z80dart_c_w )
379   case Z80DART_WR5_TX_WORD_LENGTH_7:
380      bits = 7;
381
382   case Z80DART_WR5_TX_WORD_LENGTH_8:
383      bits = 8;
384   }
385
386   return bits;
387}
388
389static void z80dart_reset_channel(const device_config *device, int channel)
294390{
295   z80dart *dart = get_safe_token( device );
296   dart_channel *chan = &dart->chan[offset];
297   int reg = chan->regs[0] & 7;
298   UINT8 old = chan->regs[reg];
391   z80dart_t *z80dart = get_safe_token(device);
392   dart_channel *ch = &z80dart->channel[channel];
299393
300   if (reg != 0 || (reg & 0xf8))
301      VPRINTF(("%04X:dart_reg_w(%c,%d) = %02X\n", activecpu_get_pc(), 'A' + offset, reg, data));
394   /* reset read registers */
395   ch->rr[0] = Z80DART_RR0_TX_BUFFER_EMPTY;
396   ch->rr[1] = ch->rr[2] = 0;
302397
303   /* write a new value to the selected register */
304   chan->regs[reg] = data;
398   /* reset write registers */
399   ch->wr[0] = ch->wr[1] = ch->wr[2] = ch->wr[3] = ch->wr[4] = ch->wr[5] = 0;
305400
306   /* clear the register number for the next write */
307   if (reg != 0)
308      chan->regs[0] &= ~7;
401   /* reset receiver */
402   ch->rx_shift = 0;
403   ch->rx_error = 0;
404   ch->rx_data_fifo[0] = ch->rx_data_fifo[1] = ch->rx_data_fifo[2] = 0;
405   ch->rx_error_fifo[0] = ch->rx_error_fifo[1] = ch->rx_error_fifo[2] = 0;
406   ch->rx_fifo = 0;
407   ch->rx_state = STATE_START;
408   ch->rx_bits = 0;
409   ch->rx_first = 1;
410   ch->rx_parity = 0;
309411
310   /* switch off the register for live state changes */
311   switch (reg)
412   /* reset transmitter */
413   ch->tx_data = 0;
414   ch->tx_shift = 0;
415   ch->tx_state = STATE_START;
416   ch->tx_bits = 0;
417   ch->tx_parity = 0;
418
419   /* reset external lines */
420   z80dart_rts_w(device, channel, 1);
421   z80dart_dtr_w(device, channel, 1);
422
423   if (channel == Z80DART_CH_A)
312424   {
313      /* DART write register 0 */
314      case 0:
315         switch (data & DART_WR0_COMMAND_MASK)
316         {
317            case DART_WR0_COMMAND_CH_RESET:
318               VPRINTF(("%04X:DART reset channel %c\n", activecpu_get_pc(), 'A' + offset));
319               reset_channel(device, offset);
320               interrupt_check(device);
321               break;
425      /* reset interrupt logic */
426      int i;
322427
323            case DART_WR0_COMMAND_RES_STATUS_INT:
324               dart->int_state[INT_CHA_STATUS - 4*offset] &= ~Z80_DAISY_INT;
325               interrupt_check(device);
326               break;
428      for (i = 0; i < 8; i++)
429      {
430         z80dart->int_state[i] = 0;
431      }
327432
328            case DART_WR0_COMMAND_ENA_RX_INT:
329               chan->int_on_next_rx = TRUE;
330               interrupt_check(device);
331               break;
433      z80dart_check_interrupt(device);
434   }
435}
332436
333            case DART_WR0_COMMAND_RES_TX_INT:
334               dart->int_state[INT_CHA_TRANSMIT - 4*offset] &= ~Z80_DAISY_INT;
335               interrupt_check(device);
336               break;
437/***************************************************************************
438    SERIAL RECEIVE
439***************************************************************************/
337440
338            case DART_WR0_COMMAND_RES_ERROR:
339               dart->int_state[INT_CHA_ERROR - 4*offset] &= ~Z80_DAISY_INT;
340               interrupt_check(device);
341               break;
342         }
343         break;
441static int detect_start_bit(const device_config *device, int channel)
442{
443   z80dart_t *z80dart = get_safe_token(device);
444   dart_channel *ch = &z80dart->channel[channel];
445   
446   if (!(ch->wr[3] & Z80DART_WR3_RX_ENABLE))
447      return 0;
344448
345      /* DART write register 1 */
346      case 1:
347         interrupt_check(device);
348         break;
449   return !z80dart_rxd_r(device, channel);
450}
349451
350      /* DART write register 5 */
351      case 5:
352         if (((old ^ data) & DART_WR5_DTR) && dart->dtr_changed_cb)
353            (*dart->dtr_changed_cb)(device, offset, (data & DART_WR5_DTR) != 0);
354         if (((old ^ data) & DART_WR5_SEND_BREAK) && dart->break_changed_cb)
355            (*dart->break_changed_cb)(device, offset, (data & DART_WR5_SEND_BREAK) != 0);
356         if (((old ^ data) & DART_WR5_RTS) && dart->rts_changed_cb)
357            (*dart->rts_changed_cb)(device, offset, (data & DART_WR5_RTS) != 0);
358         break;
452static void shift_data_in(const device_config *device, int channel)
453{
454   z80dart_t *z80dart = get_safe_token(device);
455   dart_channel *ch = &z80dart->channel[channel];
456
457   if (ch->rx_bits < 8)
458   {
459      int rxd = z80dart_rxd_r(device, channel);
460
461      ch->rx_shift >>= 1;
462      ch->rx_shift = (rxd << 7) | (ch->rx_shift & 0x7f);
463      ch->rx_parity ^= rxd;
464      ch->rx_bits++;
359465   }
360466}
361467
468static int character_completed(const device_config *device, int channel)
469{
470   z80dart_t *z80dart = get_safe_token(device);
471   dart_channel *ch = &z80dart->channel[channel];
362472
363/*-------------------------------------------------
364    z80dart_c_r - read from a control register
365-------------------------------------------------*/
473   return ch->rx_bits == z80dart_get_rx_word_length(device, channel);
474}
366475
367READ8_DEVICE_HANDLER( z80dart_c_r )
476static void detect_parity_error(const device_config *device, int channel)
368477{
369   z80dart *dart = get_safe_token( device );
370   dart_channel *chan = &dart->chan[offset];
371   int reg = chan->regs[0] & 7;
372   UINT8 result = chan->status[reg];
478   z80dart_t *z80dart = get_safe_token(device);
479   dart_channel *ch = &z80dart->channel[channel];
480   
481   int rxd = z80dart_rxd_r(device, channel);
482   int parity = (ch->wr[1] & Z80DART_WR4_PARITY_EVEN) ? 1 : 0;
373483
374   /* switch off the register for live state changes */
375   switch (reg)
484   if (rxd != (ch->rx_parity ^ parity))
376485   {
377      /* DART read register 0 */
378      case 0:
379         result &= ~DART_RR0_INT_PENDING;
380         if (z80dart_irq_state(device) & Z80_DAISY_INT)
381            result |= DART_RR0_INT_PENDING;
486      /* parity error detected */
487      ch->rx_error |= Z80DART_RR1_PARITY_ERROR;
488
489      switch (ch->wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK)
490      {
491      case Z80DART_WR1_RX_INT_FIRST:
492         if (!ch->rx_first)
493         {
494            z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
495         }
382496         break;
497     
498      case Z80DART_WR1_RX_INT_ALL_PARITY:
499         z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
500         break;
501     
502      case Z80DART_WR1_RX_INT_ALL:
503         z80dart_trigger_interrupt(device, channel, INT_RECEIVE);
504         break;
505      }
383506   }
507}
384508
385   VPRINTF(("%04X:dart_reg_r(%c,%d) = %02x\n", activecpu_get_pc(), 'A' + offset, reg, chan->status[reg]));
509static void detect_framing_error(const device_config *device, int channel)
510{
511   z80dart_t *z80dart = get_safe_token(device);
512   dart_channel *ch = &z80dart->channel[channel];
513   
514   int rxd = z80dart_rxd_r(device, channel);
386515
387   return chan->status[reg];
516   if (!rxd)
517   {
518      /* framing error detected */
519      ch->rx_error |= Z80DART_RR1_FRAMING_ERROR;
520
521      switch (ch->wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK)
522      {
523      case Z80DART_WR1_RX_INT_FIRST:
524         if (!ch->rx_first)
525         {
526            z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
527         }
528         break;
529     
530      case Z80DART_WR1_RX_INT_ALL_PARITY:
531      case Z80DART_WR1_RX_INT_ALL:
532         z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
533         break;
534      }
535   }
388536}
389537
538static void receive(const device_config *device, int channel)
539{
540   z80dart_t *z80dart = get_safe_token(device);
541   dart_channel *ch = &z80dart->channel[channel];
542   
543   float stop_bits = z80dart_get_stop_bits(device, channel);
390544
545   switch (ch->rx_state)
546   {
547   case STATE_START:
548      /* check for start bit */
549      if (detect_start_bit(device, channel))
550      {
551         /* start bit detected */
552         ch->rx_shift = 0;
553         ch->rx_error = 0;
554         ch->rx_bits = 0;
555         ch->rx_parity = 0;
391556
557         /* next bit is a data bit */
558         ch->rx_state = STATE_DATA;
559      }
560      break;
392561
562   case STATE_DATA:
563      /* shift bit into shift register */
564      shift_data_in(device, channel);
565     
566      if (character_completed(device, channel))
567      {
568         /* all data bits received */
569         if (ch->wr[4] & Z80DART_WR4_PARITY_ENABLE)
570         {
571            /* next bit is the parity bit */
572            ch->rx_state = STATE_PARITY;
573         }
574         else
575         {
576            /* next bit is a STOP bit */
577            if (stop_bits == 1)
578               ch->rx_state = STATE_STOP2;
579            else
580               ch->rx_state = STATE_STOP;
581         }
582      }
583      break;
584
585   case STATE_PARITY:
586      /* shift bit into shift register */
587      shift_data_in(device, channel);
588
589      /* check for parity error */
590      detect_parity_error(device, channel);
591
592      /* next bit is a STOP bit */
593      if (stop_bits == 1)
594         ch->rx_state = STATE_STOP2;
595      else
596         ch->rx_state = STATE_STOP;
597      break;
598
599   case STATE_STOP:
600      /* shift bit into shift register */
601      shift_data_in(device, channel);
602
603      /* check for framing error */
604      detect_framing_error(device, channel);
605
606      /* next bit is the second STOP bit */
607      ch->rx_state = STATE_STOP2;
608      break;
609
610   case STATE_STOP2:
611      /* shift bit into shift register */
612      shift_data_in(device, channel);
613
614      /* check for framing error */
615      detect_framing_error(device, channel);
616
617      /* store data into FIFO */
618      z80dart_receive_data(device, channel, ch->rx_shift);
619
620      /* next bit is the START bit */
621      ch->rx_state = STATE_START;
622      break;
623   }
624}
625
393626/***************************************************************************
394    DATA REGISTER READ/WRITE
627    SERIAL TRANSMIT
395628***************************************************************************/
396629
397/*-------------------------------------------------
398    z80dart_d_w - write to a data register
399-------------------------------------------------*/
630#define TXD(state) z80dart_txd_w(device, channel, 1);
400631
401WRITE8_DEVICE_HANDLER( z80dart_d_w )
632static void transmit(const device_config *device, int channel)
402633{
403   z80dart *dart = get_safe_token( device );
404   dart_channel *chan = &dart->chan[offset];
634   z80dart_t *z80dart = get_safe_token(device);
635   dart_channel *ch = &z80dart->channel[channel];
636   
637   int word_length = z80dart_get_tx_word_length(device, channel);
638   float stop_bits = z80dart_get_stop_bits(device, channel);
405639
406   VPRINTF(("%04X:dart_data_w(%c) = %02X\n", activecpu_get_pc(), 'A' + offset, data));
640   switch (ch->tx_state)
641   {
642   case STATE_START:
643      if ((ch->wr[5] & Z80DART_WR5_TX_ENABLE) && !(ch->rr[0] & Z80DART_RR0_TX_BUFFER_EMPTY))
644      {
645         /* transmit start bit */
646         TXD(0);
407647
408   /* if tx not enabled, just ignore it */
409   if (!(chan->regs[5] & DART_WR5_TX_ENABLE))
410      return;
648         ch->tx_bits = 0;
649         ch->tx_shift = ch->tx_data;
411650
412   /* update the status register */
413   chan->status[0] &= ~DART_RR0_TX_BUFFER_EMPTY;
651         /* empty transmit buffer */
652         ch->rr[0] |= Z80DART_RR0_TX_BUFFER_EMPTY;
414653
415   /* reset the transmit interrupt */
416   dart->int_state[INT_CHA_TRANSMIT - 4*offset] &= ~Z80_DAISY_INT;
417   interrupt_check(device);
654         if (ch->wr[1] & Z80DART_WR1_TX_INT_ENABLE)
655            z80dart_trigger_interrupt(device, channel, INT_TRANSMIT);
418656
419   /* stash the character */
420   chan->outbuf = data;
421}
657         ch->tx_state = STATE_DATA;
658      }
659      else if (ch->wr[5] & Z80DART_WR5_SEND_BREAK)
660      {
661         /* transmit break */
662         TXD(0);
663      }
664      else
665      {
666         /* transmit marking line */
667         TXD(1);
668      }
422669
670      break;
423671
424/*-------------------------------------------------
425    z80dart_d_r - read from a data register
426-------------------------------------------------*/
672   case STATE_DATA:
673      /* transmit data bit */
674      TXD(BIT(ch->tx_shift, 0));
427675
428READ8_DEVICE_HANDLER( z80dart_d_r )
429{
430   z80dart *dart = get_safe_token( device );
431   dart_channel *chan = &dart->chan[offset];
676      /* shift data */
677      ch->tx_shift >>= 1;
678      ch->tx_bits++;
432679
433   /* update the status register */
434   chan->status[0] &= ~DART_RR0_RX_CHAR_AVAILABLE;
680      if (ch->rx_bits == word_length)
681      {
682         if (ch->wr[4] & Z80DART_WR4_PARITY_ENABLE)
683            ch->tx_state = STATE_PARITY;
684         else
685         {
686            if (stop_bits == 1)
687               ch->tx_state = STATE_STOP2;
688            else
689               ch->tx_state = STATE_STOP;
690         }
691      }
692      break;
435693
436   /* reset the receive interrupt */
437   dart->int_state[INT_CHA_RECEIVE - 4*offset] &= ~Z80_DAISY_INT;
438   interrupt_check(device);
694   case STATE_PARITY:
695      // TODO: calculate parity
696      if (stop_bits == 1)
697         ch->tx_state = STATE_STOP2;
698      else
699         ch->tx_state = STATE_STOP;
700      break;
439701
440   VPRINTF(("%04X:dart_data_r(%c) = %02X\n", activecpu_get_pc(), 'A' + offset, chan->inbuf));
702   case STATE_STOP:
703      /* transmit stop bit */
704      TXD(1);
441705
442   return chan->inbuf;
443}
706      ch->tx_state = STATE_STOP2;
707      break;
444708
709   case STATE_STOP2:
710      /* transmit stop bit */
711      TXD(1);
445712
713      /* if transmit buffer is empty */
714      if (ch->rr[0] & Z80DART_RR0_TX_BUFFER_EMPTY)
715      {
716         /* then all characters have been sent */
717         ch->rr[1] |= Z80DART_RR1_ALL_SENT;
446718
719         /* when the RTS bit is reset, the _RTS output goes high after the transmitter empties */
720         if (!ch->rts)
721            z80dart_rts_w(device, channel, 1);
722      }
723
724      ch->tx_state = STATE_START;
725      break;
726   }
727}
728
447729/***************************************************************************
448    CONTROL LINE READ/WRITE
730    CONTROL REGISTER READ/WRITE
449731***************************************************************************/
450732
451/*-------------------------------------------------
452    z80dart_get_dtr - return the state of the DTR
453    line
454-------------------------------------------------*/
455
456int z80dart_get_dtr(const device_config *device, int ch)
733READ8_DEVICE_HANDLER( z80dart_c_r )
457734{
458   z80dart *dart = get_safe_token( device );
459   dart_channel *chan = &dart->chan[ch];
460   return ((chan->regs[5] & DART_WR5_DTR) != 0);
461}
735   z80dart_t *z80dart = get_safe_token(device);
736   int channel = offset & 0x01;
737   dart_channel *ch = &z80dart->channel[channel];
738   UINT8 data = 0;
462739
740   int reg = ch->wr[0] & Z80DART_WR0_REGISTER_MASK;
463741
464/*-------------------------------------------------
465    z80dart_get_rts - return the state of the RTS
466    line
467-------------------------------------------------*/
742   switch (reg)
743   {
744   case 0:
745   case 1:
746      data = ch->rr[reg];
747      break;
468748
469int z80dart_get_rts(const device_config *device, int ch)
470{
471   z80dart *dart = get_safe_token( device );
472   dart_channel *chan = &dart->chan[ch];
473   return ((chan->regs[5] & DART_WR5_RTS) != 0);
474}
749   case 2:
750      /* channel B only */
751      data = z80dart->channel[Z80DART_CH_B].rr[reg];
752      break;
753   }
475754
755   LOGERROR("Z80DART \"%s\" Channel %c : Control Register Read '%02x'\n", device->tag, 'A' + channel, data);
476756
477/*-------------------------------------------------
478    z80dart_set_cts - set the state of the CTS
479    line
480-------------------------------------------------*/
757   return data;
758}
481759
482static TIMER_CALLBACK(change_input_line)
760WRITE8_DEVICE_HANDLER( z80dart_c_w )
483761{
484   const device_config *device = ptr;
485   z80dart *dart = get_safe_token( device );
486   dart_channel *chan = &dart->chan[param & 1];
487   UINT8 line = (param >> 8) & 0xff;
488   int state = (param >> 7) & 1;
489   int ch = param & 1;
490   UINT8 old;
491   char linename[4];
762   z80dart_t *z80dart = get_safe_token(device);
763   int channel = offset & 0x01;
764   dart_channel *ch = &z80dart->channel[channel];
492765
493   switch (line)
766   int reg = ch->wr[0] & Z80DART_WR0_REGISTER_MASK;
767
768   LOGERROR("Z80DART \"%s\" Channel %c : Control Register Write '%02x'\n", device->tag, 'A' + channel, data);
769
770   /* write data to selected register */
771   ch->wr[reg] = data;
772
773   if (reg != 0)
494774   {
495   case DART_RR0_CTS:
496      sprintf(linename, "%s", "CTS");
775      /* mask out register index */
776      ch->wr[0] &= ~Z80DART_WR0_REGISTER_MASK;
777   }
778
779   switch (reg)
780   {
781   case 0:
782      switch (data & Z80DART_WR0_COMMAND_MASK)
783      {
784      case Z80DART_WR0_RESET_EXT_STATUS:
785         /* reset external/status interrupt */
786         ch->rr[0] &= ~(Z80DART_RR0_DCD | Z80DART_RR0_RI | Z80DART_RR0_CTS | Z80DART_RR0_BREAK);
787         LOGERROR("Z80DART \"%s\" Channel %c : Reset External/Status Interrupt\n", device->tag, 'A' + channel);
788         break;
789
790      case Z80DART_WR0_CHANNEL_RESET:
791         /* channel reset */
792         LOGERROR("Z80DART \"%s\" Channel %c : Channel Reset\n", device->tag, 'A' + channel);
793         z80dart_reset_channel(device, channel);
794         break;
795
796      case Z80DART_WR0_ENABLE_INT_NEXT_RX:
797         /* enable interrupt on next receive character */
798         LOGERROR("Z80DART \"%s\" Channel %c : Enable Interrupt on Next Received Character\n", device->tag, 'A' + channel);
799         ch->rx_first = 1;
800         break;
801
802      case Z80DART_WR0_RESET_TX_INT:
803         /* reset transmitter interrupt pending */
804         LOGERROR("Z80DART \"%s\" Channel %c : Reset Transmitter Interrupt Pending\n", device->tag, 'A' + channel);
805         break;
806
807      case Z80DART_WR0_ERROR_RESET:
808         /* error reset */
809         LOGERROR("Z80DART \"%s\" Channel %c : Error Reset\n", device->tag, 'A' + channel);
810         ch->rr[1] &= ~(Z80DART_RR1_FRAMING_ERROR | Z80DART_RR1_RX_OVERRUN_ERROR | Z80DART_RR1_PARITY_ERROR);
811         break;
812
813      case Z80DART_WR0_RETURN_FROM_INT:
814         /* return from interrupt */
815         LOGERROR("Z80DART \"%s\" Channel %c : Return from Interrupt\n", device->tag, 'A' + channel);
816         z80dart_irq_reti(device);
817         break;
818      }
497819      break;
498   case DART_RR0_DCD:
499      sprintf(linename, "%s", "DCD");
820
821   case 1:
822      LOGERROR("Z80DART \"%s\" Channel %c : External Interrupt Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR1_EXT_INT_ENABLE) ? 1 : 0);
823      LOGERROR("Z80DART \"%s\" Channel %c : Transmit Interrupt Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR1_TX_INT_ENABLE) ? 1 : 0);
824      LOGERROR("Z80DART \"%s\" Channel %c : Status Affects Vector %u\n", device->tag, 'A' + channel, (data & Z80DART_WR1_STATUS_VECTOR) ? 1 : 0);
825      LOGERROR("Z80DART \"%s\" Channel %c : Wait/Ready Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR1_WRDY_ENABLE) ? 1 : 0);
826     
827      switch (data & Z80DART_WR1_RX_INT_ENABLE_MASK)
828      {
829      case Z80DART_WR1_RX_INT_DISABLE:
830         LOGERROR("Z80DART \"%s\" Channel %c : Receiver Interrupt Disabled\n", device->tag, 'A' + channel);
831         break;
832
833      case Z80DART_WR1_RX_INT_FIRST:
834         LOGERROR("Z80DART \"%s\" Channel %c : Receiver Interrupt on First Character\n", device->tag, 'A' + channel);
835         break;
836
837      case Z80DART_WR1_RX_INT_ALL_PARITY:
838         LOGERROR("Z80DART \"%s\" Channel %c : Receiver Interrupt on All Characters, Parity Affects Vector\n", device->tag, 'A' + channel);
839         break;
840
841      case Z80DART_WR1_RX_INT_ALL:
842         LOGERROR("Z80DART \"%s\" Channel %c : Receiver Interrupt on All Characters\n", device->tag, 'A' + channel);
843         break;
844      }
845
846      z80dart_check_interrupt(device);
500847      break;
501   case DART_RR0_RI:
502      sprintf(linename, "%s", "RI");
848
849   case 2:
850      /* interrupt vector */
851      z80dart_check_interrupt(device);
852      LOGERROR("Z80DART \"%s\" Channel %c : Interrupt Vector %02x\n", device->tag, 'A' + channel, data);
503853      break;
504   }
505   VPRINTF(("dart_change_input_line(%c, %s) = %d\n", 'A' + ch, linename, state));
506854
507   /* remember the old value */
508   old = chan->status[0];
855   case 3:
856      LOGERROR("Z80DART \"%s\" Channel %c : Receiver Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR3_RX_ENABLE) ? 1 : 0);
857      LOGERROR("Z80DART \"%s\" Channel %c : Auto Enables %u\n", device->tag, 'A' + channel, (data & Z80DART_WR3_AUTO_ENABLES) ? 1 : 0);
858      LOGERROR("Z80DART \"%s\" Channel %c : Receiver Bits/Character %u\n", device->tag, 'A' + channel, z80dart_get_rx_word_length(device, channel));
859      break;
509860
510   /* set the bit in the status register */
511   chan->status[0] &= ~line;
512   if (state)
513      chan->status[0] |= line;
861   case 4:
862      LOGERROR("Z80DART \"%s\" Channel %c : Parity Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR4_PARITY_ENABLE) ? 1 : 0);
863      LOGERROR("Z80DART \"%s\" Channel %c : Parity %s\n", device->tag, 'A' + channel, (data & Z80DART_WR4_PARITY_EVEN) ? "Even" : "Odd");
864      LOGERROR("Z80DART \"%s\" Channel %c : Stop Bits %f\n", device->tag, 'A' + channel, z80dart_get_stop_bits(device, channel));
865      LOGERROR("Z80DART \"%s\" Channel %c : Clock Mode %uX\n", device->tag, 'A' + channel, z80dart_get_clock_mode(device, channel));
866      break;
514867
515   /* if state change interrupts are enabled, signal */
516   if (((old ^ chan->status[0]) & line) && (chan->regs[1] & DART_WR1_STATUSINT_ENABLE))
517   {
518      dart->int_state[INT_CHA_STATUS - 4*ch] |= Z80_DAISY_INT;
519      interrupt_check(device);
868   case 5:
869      LOGERROR("Z80DART \"%s\" Channel %c : Transmitter Enable %u\n", device->tag, 'A' + channel, (data & Z80DART_WR5_TX_ENABLE) ? 1 : 0);
870      LOGERROR("Z80DART \"%s\" Channel %c : Transmitter Bits/Character %u\n", device->tag, 'A' + channel, z80dart_get_tx_word_length(device, channel));
871      LOGERROR("Z80DART \"%s\" Channel %c : Send Break %u\n", device->tag, 'A' + channel, (data & Z80DART_WR5_SEND_BREAK) ? 1 : 0);
872      LOGERROR("Z80DART \"%s\" Channel %c : Request to Send %u\n", device->tag, 'A' + channel, (data & Z80DART_WR5_RTS) ? 1 : 0);
873      LOGERROR("Z80DART \"%s\" Channel %c : Data Terminal Ready %u\n", device->tag, 'A' + channel, (data & Z80DART_WR5_DTR) ? 1 : 0);
874
875      if (data & Z80DART_WR5_RTS)
876      {
877         /* when the RTS bit is set, the _RTS output goes low */
878         z80dart_rts_w(device, channel, 0);
879
880         ch->rts = 1;
881      }
882      else
883      {
884         /* when the RTS bit is reset, the _RTS output goes high after the transmitter empties */
885         ch->rts = 0;
886      }
887
888      /* data terminal ready output follows the state programmed into the DTR bit*/
889      ch->dtr = (data & Z80DART_WR5_DTR) ? 0 : 1;
890      z80dart_dtr_w(device, channel, ch->dtr);
891      break;
520892   }
521893}
522894
895/***************************************************************************
896    DATA REGISTER READ/WRITE
897***************************************************************************/
523898
524/*-------------------------------------------------
525    z80dart_set_cts - set the state of the CTS
526    line
527-------------------------------------------------*/
528
529void z80dart_set_cts(const device_config *device, int ch, int state)
899READ8_DEVICE_HANDLER( z80dart_d_r )
530900{
531   /* operate deferred */
532   timer_set(attotime_zero, (void *)device, (DART_RR0_CTS << 8) + (state != 0) * 0x80 + ch, change_input_line);
533}
901   z80dart_t *z80dart = get_safe_token(device);
902   int channel = offset & 0x01;
903   dart_channel *ch = &z80dart->channel[channel];
904   UINT8 data = 0;
534905
906   if (ch->rx_fifo >= 0)
907   {
908      /* load data from the FIFO */
909      data = ch->rx_data_fifo[ch->rx_fifo];
535910
536/*-------------------------------------------------
537    z80dart_set_dcd - set the state of the DCD
538    line
539-------------------------------------------------*/
911      /* load error status from the FIFO, retain overrun and parity errors */
912      ch->rr[1] = (ch->rr[1] & (Z80DART_RR1_RX_OVERRUN_ERROR | Z80DART_RR1_PARITY_ERROR)) | ch->rx_error_fifo[ch->rx_fifo];
540913
541void z80dart_set_dcd(const device_config *device, int ch, int state)
542{
543   /* operate deferred */
544   timer_set(attotime_zero, (void *)device, (DART_RR0_DCD << 8) + (state != 0) * 0x80 + ch, change_input_line);
914      /* decrease FIFO pointer */
915      ch->rx_fifo--;
916
917      if (ch->rx_fifo < 0)
918      {
919         /* no more characters available in the FIFO */
920         ch->rr[0] &= ~ Z80DART_RR0_RX_CHAR_AVAILABLE;
921      }
922   }
923
924   LOGERROR("Z80DART \"%s\" Channel %c : Data Register Read '%02x'\n", device->tag, 'A' + channel, data);
925
926   return data;
545927}
546928
929WRITE8_DEVICE_HANDLER( z80dart_d_w )
930{
931   z80dart_t *z80dart = get_safe_token(device);
932   int channel = offset & 0x01;
933   dart_channel *ch = &z80dart->channel[channel];
547934
548/*-------------------------------------------------
549    z80dart_set_ri - set the state of the RIA
550    line
551-------------------------------------------------*/
935   ch->tx_data = data;
936   
937   ch->rr[0] &= ~Z80DART_RR0_TX_BUFFER_EMPTY;
938   ch->rr[1] &= ~Z80DART_RR1_ALL_SENT;
552939
553void z80dart_set_ri(const device_config *device, int ch, int state)
554{
555   /* operate deferred */
556   timer_set(attotime_zero, (void *)device, (DART_RR0_RI << 8) + (state != 0) * 0x80 + ch, change_input_line);
940   LOGERROR("Z80DART \"%s\" Channel %c : Data Register Write '%02x'\n", device->tag, 'A' + channel, data);
557941}
558942
943/***************************************************************************
944    CONTROL LINE READ/WRITE
945***************************************************************************/
559946
560/*-------------------------------------------------
561    z80dart_receive_data - receive data on the
562    input lines
563-------------------------------------------------*/
564
565void z80dart_receive_data(const device_config *device, int ch, UINT8 data)
947void z80dart_receive_data(const device_config *device, int channel, UINT8 data)
566948{
567   z80dart *dart = get_safe_token( device );
568   dart_channel *chan = &dart->chan[ch];
569   int newinptr;
949   z80dart_t *z80dart = get_safe_token(device);
950   dart_channel *ch = &z80dart->channel[channel];
570951
571   /* put it on the queue */
572   newinptr = (chan->receive_inptr + 1) % ARRAY_LENGTH(chan->receive_buffer);
573   if (newinptr != chan->receive_outptr)
952   LOGERROR("Z80DART \"%s\" Channel %c : Receive Data Byte '%02x'\n", device->tag, 'A' + channel, data);
953
954   if (ch->rx_fifo == 2)
574955   {
575      chan->receive_buffer[chan->receive_inptr] = data;
576      chan->receive_inptr = newinptr;
956      /* receive overrun error detected */
957      ch->rx_error |= Z80DART_RR1_RX_OVERRUN_ERROR;
958
959      switch (ch->wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK)
960      {
961      case Z80DART_WR1_RX_INT_FIRST:
962         if (!ch->rx_first)
963         {
964            z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
965         }
966         break;
967     
968      case Z80DART_WR1_RX_INT_ALL_PARITY:
969      case Z80DART_WR1_RX_INT_ALL:
970         z80dart_trigger_interrupt(device, channel, INT_SPECIAL);
971         break;
972      }
577973   }
578974   else
579      logerror("z80dart_receive_data: buffer overrun\n");
975   {
976      ch->rx_fifo++;
977   }
978
979   /* store received character and error status into FIFO */
980   ch->rx_data_fifo[ch->rx_fifo] = data;
981   ch->rx_error_fifo[ch->rx_fifo] = ch->rx_error;
982
983   ch->rr[0] |= Z80DART_RR0_RX_CHAR_AVAILABLE;
984
985   /* receive interrupt */
986   switch (ch->wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK)
987   {
988   case Z80DART_WR1_RX_INT_FIRST:
989      if (ch->rx_first)
990      {
991         z80dart_trigger_interrupt(device, channel, INT_RECEIVE);
992
993         ch->rx_first = 0;
994      }
995      break;
996
997   case Z80DART_WR1_RX_INT_ALL_PARITY:
998   case Z80DART_WR1_RX_INT_ALL:
999      z80dart_trigger_interrupt(device, channel, INT_RECEIVE);
1000      break;
1001   }
5801002}
5811003
1004void z80dart_cts_w(const device_config *device, int channel, int state)
1005{
1006   z80dart_t *z80dart = get_safe_token(device);
1007   dart_channel *ch = &z80dart->channel[channel];
5821008
583/*-------------------------------------------------
584    serial_callback - callback to pump
585    data through
586-------------------------------------------------*/
1009   LOGERROR("Z80DART \"%s\" Channel %c : CTS %u\n", device->tag, 'A' + channel, state);
5871010
588static TIMER_CALLBACK(serial_callback)
1011   if (ch->cts != state)
1012   {
1013      /* enable transmitter if in auto enables mode */
1014      if (!state)
1015         if (ch->wr[3] & Z80DART_WR3_AUTO_ENABLES)
1016            ch->wr[5] |= Z80DART_WR5_TX_ENABLE;
1017
1018      /* set clear to send */
1019      ch->cts = state;
1020
1021      if (ch->cts)
1022         ch->rr[0] |= Z80DART_RR0_CTS;
1023
1024      /* trigger interrupt */
1025      z80dart_trigger_interrupt(device, channel, INT_EXTERNAL);
1026   }
1027}
1028
1029void z80dart_dcd_w(const device_config *device, int channel, int state)
5891030{
590   const device_config *device = ptr;
591   z80dart *dart = get_safe_token( device );
592   dart_channel *chan = &dart->chan[param & 1];
593   int ch = param & 1;
594   int data = -1;
1031   z80dart_t *z80dart = get_safe_token(device);
1032   dart_channel *ch = &z80dart->channel[channel];
5951033
596   /* first perform any outstanding transmits */
597   if (chan->outbuf != -1)
1034   LOGERROR("Z80DART \"%s\" Channel %c : DCD %u\n", device->tag, 'A' + channel, state);
1035
1036   if (ch->dcd != state)
5981037   {
599      VPRINTF(("serial_callback(%c): Transmitting %02x\n", 'A' + ch, chan->outbuf));
1038      /* enable receiver if in auto enables mode */
1039      if (!state)
1040         if (ch->wr[3] & Z80DART_WR3_AUTO_ENABLES)
1041            ch->wr[3] |= Z80DART_WR3_RX_ENABLE;
6001042
601      /* actually transmit the character */
602      if (dart->transmit_cb != NULL)
603         (*dart->transmit_cb)(device, ch, chan->outbuf);
1043      /* set data carrier detect */
1044      ch->dcd = state;
6041045
605      /* update the status register */
606      chan->status[0] |= DART_RR0_TX_BUFFER_EMPTY;
1046      if (ch->dcd)
1047         ch->rr[0] |= Z80DART_RR0_DCD;
6071048
608      /* set the transmit buffer empty interrupt if enabled */
609      if (chan->regs[1] & DART_WR1_TXINT_ENABLE)
610      {
611         dart->int_state[INT_CHA_TRANSMIT - 4*ch] |= Z80_DAISY_INT;
612         interrupt_check(device);
613      }
1049      /* trigger interrupt */
1050      if (ch->wr[1] & Z80DART_WR1_EXT_INT_ENABLE)
1051         z80dart_trigger_interrupt(device, channel, INT_EXTERNAL);
1052   }
1053}
6141054
615      /* reset the output buffer */
616      chan->outbuf = -1;
1055void z80dart_ri_w(const device_config *device, int channel, int state)
1056{
1057   z80dart_t *z80dart = get_safe_token(device);
1058   dart_channel *ch = &z80dart->channel[channel];
1059
1060   LOGERROR("Z80DART \"%s\" Channel %c : RI %u\n", device->tag, 'A' + channel, state);
1061
1062   if (ch->ri != state)
1063   {
1064      /* set ring indicator state */
1065      ch->ri = state;
1066
1067      if (ch->ri)
1068         ch->rr[0] |= Z80DART_RR0_RI;
1069
1070      /* trigger interrupt */
1071      if (ch->wr[1] & Z80DART_WR1_EXT_INT_ENABLE)
1072         z80dart_trigger_interrupt(device, channel, INT_EXTERNAL);
6171073   }
1074}
6181075
619   /* ask the polling callback if there is data to receive */
620   if (dart->receive_poll_cb != NULL)
621      data = (*dart->receive_poll_cb)(device, ch);
1076/***************************************************************************
1077    CLOCK MANAGEMENT
1078***************************************************************************/
6221079
623   /* if we have buffered data, pull it */
624   if (chan->receive_inptr != chan->receive_outptr)
1080void z80dart_rxca_w(const device_config *device)
1081{
1082   z80dart_t *z80dart = get_safe_token(device);
1083   dart_channel *ch = &z80dart->channel[Z80DART_CH_A];
1084
1085   int clocks = z80dart_get_clock_mode(device, Z80DART_CH_A);
1086
1087   LOGERROR("Z80DART \"%s\" Channel A : Receiver Clock Pulse\n", device->tag);
1088   
1089   ch->rx_clock++;
1090
1091   if (ch->rx_clock == clocks)
6251092   {
626      data = chan->receive_buffer[chan->receive_outptr];
627      chan->receive_outptr = (chan->receive_outptr + 1) % ARRAY_LENGTH(chan->receive_buffer);
1093      ch->rx_clock = 0;
1094
1095      /* receive data */
1096      receive(device, Z80DART_CH_A);
6281097   }
1098}
6291099
630   /* if we have data, receive it */
631   if (data != -1)
1100void z80dart_txca_w(const device_config *device)
1101{
1102   z80dart_t *z80dart = get_safe_token(device);
1103   dart_channel *ch = &z80dart->channel[Z80DART_CH_A];
1104
1105   int clocks = z80dart_get_clock_mode(device, Z80DART_CH_A);
1106
1107   LOGERROR("Z80DART \"%s\" Channel A : Transmitter Clock Pulse\n", device->tag);
1108   
1109   ch->tx_clock++;
1110
1111   if (ch->tx_clock == clocks)
6321112   {
633      VPRINTF(("serial_callback(%c): Receiving %02x\n", 'A' + ch, data));
1113      ch->tx_clock = 0;
6341114
635      /* if rx not enabled, just ignore it */
636      if (!(chan->regs[3] & DART_WR3_RX_ENABLE))
637      {
638         VPRINTF(("  (ignored because receive is disabled)\n"));
639         return;
640      }
1115      /* transmit data */
1116      transmit(device, Z80DART_CH_A);
1117   }
1118}
6411119
642      /* stash the data and update the status */
643      chan->inbuf = data;
644      chan->status[0] |= DART_RR0_RX_CHAR_AVAILABLE;
1120void z80dart_rxtxcb_w(const device_config *device)
1121{
1122   z80dart_t *z80dart = get_safe_token(device);
1123   dart_channel *ch = &z80dart->channel[Z80DART_CH_B];
6451124
646      /* update our interrupt state */
647      switch (chan->regs[1] & DART_WR1_RXINT_MASK)
648      {
649         case DART_WR1_RXINT_FIRST:
650            if (!chan->int_on_next_rx)
651               break;
1125   int clocks = z80dart_get_clock_mode(device, Z80DART_CH_B);
6521126
653         case DART_WR1_RXINT_ALL_NOPARITY:
654         case DART_WR1_RXINT_ALL_PARITY:
655            dart->int_state[INT_CHA_RECEIVE - 4*ch] |= Z80_DAISY_INT;
656            interrupt_check(device);
657            break;
658      }
659      chan->int_on_next_rx = FALSE;
1127   LOGERROR("Z80DART \"%s\" Channel A : Receiver/Transmitter Clock Pulse\n", device->tag);
1128   
1129   ch->rx_clock++;
1130   ch->tx_clock++;
1131
1132   if (ch->rx_clock == clocks)
1133   {
1134      ch->rx_clock = 0;
1135      ch->tx_clock = 0;
1136
1137      /* receive and transmit data */
1138      receive(device, Z80DART_CH_B);
1139      transmit(device, Z80DART_CH_B);
6601140   }
6611141}
6621142
1143static TIMER_CALLBACK( rxca_tick )
1144{
1145   z80dart_rxca_w(ptr);
1146}
6631147
1148static TIMER_CALLBACK( txca_tick )
1149{
1150   z80dart_txca_w(ptr);
1151}
6641152
1153static TIMER_CALLBACK( rxtxcb_tick )
1154{
1155   z80dart_rxtxcb_w(ptr);
1156}
1157
6651158/***************************************************************************
6661159    DAISY CHAIN INTERFACE
6671160***************************************************************************/
6681161
669static const UINT8 int_priority[] =
670{
671   INT_CHA_RECEIVE,
672   INT_CHA_TRANSMIT,
673   INT_CHA_STATUS,
674   INT_CHA_ERROR,
675   INT_CHB_RECEIVE,
676   INT_CHB_TRANSMIT,
677   INT_CHB_STATUS,
678   INT_CHB_ERROR
679};
680
681
6821162static int z80dart_irq_state(const device_config *device)
6831163{
684   z80dart *dart = get_safe_token( device );
1164   z80dart_t *z80dart = get_safe_token( device );
6851165   int state = 0;
6861166   int i;
6871167
688   VPRINTF(("dart IRQ state = B:%d%d%d%d A:%d%d%d%d\n",
689            dart->int_state[0], dart->int_state[1], dart->int_state[2], dart->int_state[3],
690            dart->int_state[4], dart->int_state[5], dart->int_state[6], dart->int_state[7]));
1168   LOGERROR("dart IRQ state = B:%d%d%d%d A:%d%d%d%d\n",
1169            z80dart->int_state[0], z80dart->int_state[1], z80dart->int_state[2], z80dart->int_state[3],
1170            z80dart->int_state[4], z80dart->int_state[5], z80dart->int_state[6], z80dart->int_state[7]);
6911171
6921172   /* loop over all interrupt sources */
6931173   for (i = 0; i < 8; i++)
6941174   {
695      int inum = int_priority[i];
696
6971175      /* if we're servicing a request, don't indicate more interrupts */
698      if (dart->int_state[inum] & Z80_DAISY_IEO)
1176      if (z80dart->int_state[i] & Z80_DAISY_IEO)
6991177      {
7001178         state |= Z80_DAISY_IEO;
7011179         break;
7021180      }
703      state |= dart->int_state[inum];
1181      state |= z80dart->int_state[i];
7041182   }
7051183
1184   LOGERROR("Z80DART \"%s\" : Interrupt State %u\n", device->tag, state);
1185
7061186   return state;
7071187}
7081188
709
7101189static int z80dart_irq_ack(const device_config *device)
7111190{
712   z80dart *dart = get_safe_token( device );
1191   z80dart_t *z80dart = get_safe_token( device );
7131192   int i;
7141193
1194   LOGERROR("Z80DART \"%s\" Interrupt Acknowledge\n", device->tag);
1195
7151196   /* loop over all interrupt sources */
7161197   for (i = 0; i < 8; i++)
7171198   {
718      int inum = int_priority[i];
719
7201199      /* find the first channel with an interrupt requested */
721      if (dart->int_state[inum] & Z80_DAISY_INT)
1200      if (z80dart->int_state[i] & Z80_DAISY_INT)
7221201      {
723         VPRINTF(("dart IRQAck %d\n", inum));
1202         /* clear interrupt, switch to the IEO state, and update the IRQs */
1203         z80dart->int_state[i] = Z80_DAISY_IEO;
1204         z80dart->channel[Z80DART_CH_A].rr[0] &= ~Z80DART_RR0_INTERRUPT_PENDING;
1205         z80dart_check_interrupt(device);
7241206
725         /* clear interrupt, switch to the IEO state, and update the IRQs */
726         dart->int_state[inum] = Z80_DAISY_IEO;
727         interrupt_check(device);
728         return dart->chan[1].regs[2] + inum * 2;
1207         LOGERROR("Z80DART \"%s\" : Interrupt Acknowledge Vector %02x\n", device->tag, z80dart->channel[Z80DART_CH_B].rr[2]);
1208
1209         return z80dart->channel[Z80DART_CH_B].rr[2];
7291210      }
7301211   }
7311212
7321213   logerror("z80dart_irq_ack: failed to find an interrupt to ack!\n");
733   return dart->chan[1].regs[2];
1214   
1215   return z80dart->channel[Z80DART_CH_B].rr[2];
7341216}
7351217
736
7371218static void z80dart_irq_reti(const device_config *device)
7381219{
739   z80dart *dart = get_safe_token( device );
1220   z80dart_t *z80dart = get_safe_token( device );
7401221   int i;
7411222
1223   LOGERROR("Z80DART \"%s\" Return from Interrupt\n", device->tag);
1224
7421225   /* loop over all interrupt sources */
7431226   for (i = 0; i < 8; i++)
7441227   {
745      int inum = int_priority[i];
746
7471228      /* find the first channel with an IEO pending */
748      if (dart->int_state[inum] & Z80_DAISY_IEO)
1229      if (z80dart->int_state[i] & Z80_DAISY_IEO)
7491230      {
750         VPRINTF(("dart IRQReti %d\n", inum));
751
7521231         /* clear the IEO state and update the IRQs */
753         dart->int_state[inum] &= ~Z80_DAISY_IEO;
754         interrupt_check(device);
1232         z80dart->int_state[i] &= ~Z80_DAISY_IEO;
1233         z80dart_check_interrupt(device);
7551234         return;
7561235      }
7571236   }
r3481r3482
7591238   logerror("z80dart_irq_reti: failed to find an interrupt to clear IEO on!\n");
7601239}
7611240
1241/***************************************************************************
1242    READ/WRITE HANDLERS
1243***************************************************************************/
7621244
1245READ8_DEVICE_HANDLER( z80dart_r )
1246{
1247   return (offset & 2) ? z80dart_c_r(device, offset & 1) : z80dart_d_r(device, offset & 1);
1248}
1249
1250WRITE8_DEVICE_HANDLER( z80dart_w )
1251{
1252   if (offset & 2)
1253      z80dart_c_w(device, offset & 1, data);
1254   else
1255      z80dart_d_w(device, offset & 1, data);
1256}
1257
1258READ8_DEVICE_HANDLER( z80dart_alt_r )
1259{
1260   int channel = BIT(offset, 1);
1261
1262   return (offset & 1) ? z80dart_c_r(device, channel) : z80dart_d_r(device, channel);
1263}
1264
1265WRITE8_DEVICE_HANDLER( z80dart_alt_w )
1266{
1267   int channel = BIT(offset, 1);
1268
1269   if (offset & 1)
1270      z80dart_c_w(device, channel, data);
1271   else
1272      z80dart_d_w(device, channel, data);
1273}
1274
1275/***************************************************************************
1276    DEVICE INTERFACE
1277***************************************************************************/
1278
7631279static DEVICE_START( z80dart )
7641280{
7651281   const z80dart_interface *intf = device->static_config;
766   z80dart *dart = get_safe_token(device);
1282   z80dart_t *z80dart = get_safe_token(device);
1283   char unique_tag[30];
1284   int cpunum = -1;
7671285
768   dart->chan[0].receive_timer = timer_alloc(serial_callback, (void *)device);
769   dart->chan[1].receive_timer = timer_alloc(serial_callback, (void *)device);
1286   assert(intf != NULL);
1287   z80dart->intf = intf;
7701288
771   dart->irq_cb = intf->irq_cb;
772   dart->dtr_changed_cb = intf->dtr_changed_cb;
773   dart->rts_changed_cb = intf->rts_changed_cb;
774   dart->break_changed_cb = intf->break_changed_cb;
775   dart->transmit_cb = intf->transmit_cb;
776   dart->receive_poll_cb = intf->receive_poll_cb;
1289   /* get clock */
7771290
1291   if (intf->cpu != NULL)
1292   {
1293      cpunum = mame_find_cpu_index(device->machine, intf->cpu);
1294   }
1295
1296   if (cpunum != -1)
1297   {
1298      z80dart->clock = device->machine->config->cpu[cpunum].clock;
1299   }
1300   else
1301   {
1302      assert(intf->clock > 0);
1303      z80dart->clock = intf->clock;
1304   }
1305
1306   /* allocate channel A receive timer */
1307
1308   z80dart->rxca_timer = timer_alloc(rxca_tick, (void *)device);
1309
1310   if (z80dart->intf->rx_clock_a)
1311      timer_adjust_periodic(z80dart->rxca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80dart->intf->rx_clock_a));
1312
1313   /* allocate channel A transmit timer */
1314
1315   z80dart->txca_timer = timer_alloc(txca_tick, (void *)device);
1316
1317   if (z80dart->intf->tx_clock_a)
1318      timer_adjust_periodic(z80dart->txca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80dart->intf->tx_clock_a));
1319
1320   /* allocate channel B receive/transmit timer */
1321
1322   z80dart->rxtxcb_timer = timer_alloc(rxtxcb_tick, (void *)device);
1323
1324   if (z80dart->intf->rx_tx_clock_b)
1325      timer_adjust_periodic(z80dart->rxtxcb_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80dart->intf->rx_tx_clock_b));
1326
1327   /* register for state saving */
1328
1329   state_save_combine_module_and_tag(unique_tag, "z80dart", device->tag);
1330
1331   //state_save_register_item_array(unique_tag, 0, z80dart->);
1332
7781333   return DEVICE_START_OK;
7791334}
7801335
781
7821336static DEVICE_RESET( z80dart )
7831337{
784   int ch;
1338   int channel;
7851339
786   /* set up defaults */
787   for (ch = 0; ch < 2; ch++)
1340   for (channel = Z80DART_CH_A; channel <= Z80DART_CH_B; channel++)
7881341   {
789      reset_channel( device, ch );
1342      z80dart_reset_channel(device, channel);
7901343   }
791   interrupt_check(device);
1344
1345   z80dart_check_interrupt(device);
7921346}
7931347
794
7951348static DEVICE_SET_INFO( z80dart )
7961349{
7971350   switch (state)
r3481r3482
8001353   }
8011354}
8021355
803
8041356DEVICE_GET_INFO( z80dart )
8051357{
8061358   switch (state)
8071359   {
8081360      /* --- the following bits of info are returned as 64-bit signed integers --- */
809      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(z80dart);                  break;
1361      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(z80dart_t);               break;
8101362      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                           break;
8111363      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;            break;
8121364
r3481r3482
8271379      case DEVINFO_STR_CREDITS:                  info->s = "Copyright the MESS Team";         break;
8281380   }
8291381}
830
src/mess/machine/z80dart.h
r3481r3482
11/***************************************************************************
22
3    Z80 DART (Z8470) implementation
3    Z80 DART Dual Asynchronous Receiver/Transmitter implementation
44
5    Copyright (c) 2007, The MAME Team.
5    Copyright (c) 2008, The MESS Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
8****************************************************************************
9                            _____   _____
10                    D1   1 |*    \_/     | 40  D0
11                    D3   2 |             | 39  D2
12                    D5   3 |             | 38  D4
13                    D7   4 |             | 37  D6
14                  _INT   5 |             | 36  _IORQ
15                   IEI   6 |             | 35  _CE
16                   IEO   7 |             | 34  B/_A
17                   _M1   8 |             | 33  C/_D
18                   Vdd   9 |             | 32  _RD
19               _W/RDYA  10 |  Z80-DART   | 31  GND
20                  _RIA  11 |             | 30  _W/RDYB
21                  RxDA  12 |             | 29  _RIB
22                 _RxCA  13 |             | 28  RxDB
23                 _TxCA  14 |             | 27  _RxTxCB
24                  TxDA  15 |             | 26  TxDB
25                 _DTRA  16 |             | 25  _DTRB
26                 _RTSA  17 |             | 24  _RTSB
27                 _CTSA  18 |             | 23  _CTSB
28                 _DCDA  19 |             | 22  _DCDB
29                   CLK  20 |_____________| 21  _RESET
30
831***************************************************************************/
932
1033#ifndef __Z80DART_H_
1134#define __Z80DART_H_
1235
36/***************************************************************************
37    CALLBACK FUNCTION PROTOTYPES
38***************************************************************************/
1339
40typedef void (*z80dart_on_int_changed_func) (const device_config *device, int state);
41#define Z80DART_ON_INT_CHANGED(name) void name(const device_config *device, int state)
42
43typedef int (*z80dart_rxd_read_func) (const device_config *device, int channel);
44#define Z80DART_RXD_READ(name) int name(const device_config *device, int channel)
45
46typedef void (*z80dart_on_txd_changed_func) (const device_config *device, int channel, int level);
47#define Z80DART_ON_TXD_CHANGED(name) void name(const device_config *device, int channel, int level)
48
49typedef void (*z80dart_on_wrdy_changed_func) (const device_config *device, int channel, int level);
50#define Z80DART_ON_WRDY_CHANGED(name) void name(const device_config *device, int channel, int level)
51
52typedef void (*z80dart_on_rts_changed_func) (const device_config *device, int channel, int level);
53#define Z80DART_ON_RTS_CHANGED(name) void name(const device_config *device, int channel, int level)
54
55typedef void (*z80dart_on_dtr_changed_func) (const device_config *device, int channel, int level);
56#define Z80DART_ON_DTR_CHANGED(name) void name(const device_config *device, int channel, int level)
57
1458/***************************************************************************
1559    TYPE DEFINITIONS
1660***************************************************************************/
1761
62enum
63{
64   Z80DART_CH_A = 0,
65   Z80DART_CH_B
66};
67
1868typedef struct _z80dart_interface z80dart_interface;
1969struct _z80dart_interface
2070{
21   const char *cpu;
22   int baseclock;
23   void (*irq_cb)(const device_config *device, int state);
24   write8_device_func dtr_changed_cb;
25   write8_device_func rts_changed_cb;
26   write8_device_func break_changed_cb;
27   write8_device_func transmit_cb;
28   int (*receive_poll_cb)(const device_config *device, int ch);
29};
71   const char *cpu;      /* cpu tag */
72   int clock;            /* base clock */
3073
74   int rx_clock_a;         /* channel A receive clock */
75   int tx_clock_a;         /* channel A transmit clock */
76   int rx_tx_clock_b;      /* channel B receive/transmit clock */
3177
78   /* this gets called for every change of the INT pin (pin 5) */
79   z80dart_on_int_changed_func      on_int_changed;
3280
81   /* this gets called for every read of the RxDA/RxDB pins (pin 12/28) */
82   z80dart_rxd_read_func         rxd_r;
83
84   /* this gets called for every change of the TxDA/TxDB pins (pin 15/26) */
85   z80dart_on_txd_changed_func      on_txd_changed;
86
87   /* this gets called for every change of the DTRA/DTRB pins (pin 16/25) */
88   z80dart_on_dtr_changed_func      on_dtr_changed;
89
90   /* this gets called for every change of the RTSA/RTSB pins (pin 17/24) */
91   z80dart_on_rts_changed_func      on_rts_changed;
92
93   /* this gets called for every change of the WRDYA/WRDYB pins (pin 10/30) */
94   z80dart_on_wrdy_changed_func   on_wrdy_changed;
95};
96#define Z80DART_INTERFACE(name) const z80dart_interface (name)=
97
3398/***************************************************************************
3499    DEVICE CONFIGURATION MACROS
35100***************************************************************************/
r3481r3482
41106#define MDRV_Z80DART_REMOVE(_tag) \
42107   MDRV_DEVICE_REMOVE(_tag, Z80DART)
43108
44
45
46109/***************************************************************************
47110    CONTROL REGISTER READ/WRITE
48111***************************************************************************/
r3481r3482
50113WRITE8_DEVICE_HANDLER( z80dart_c_w );
51114READ8_DEVICE_HANDLER( z80dart_c_r );
52115
53
54
55116/***************************************************************************
56117    DATA REGISTER READ/WRITE
57118***************************************************************************/
r3481r3482
59120WRITE8_DEVICE_HANDLER( z80dart_d_w );
60121READ8_DEVICE_HANDLER( z80dart_d_r );
61122
123/***************************************************************************
124    CLOCK MANAGEMENT
125***************************************************************************/
62126
127void z80dart_rxca_w(const device_config *device);
128void z80dart_txca_w(const device_config *device);
129void z80dart_rxtxcb_w(const device_config *device);
63130
64131/***************************************************************************
65132    CONTROL LINE READ/WRITE
66133***************************************************************************/
67134
68int z80dart_get_dtr(const device_config *device, int ch);
69int z80dart_get_rts(const device_config *device, int ch);
70void z80dart_set_cts(const device_config *device, int ch, int state);
71void z80dart_set_dcd(const device_config *device, int ch, int state);
72void z80dart_set_ri(const device_config *device, int ch, int state);
73void z80dart_receive_data(const device_config *device, int ch, UINT8 data);
135void z80dart_receive_data(const device_config *device, int channel, UINT8 data);
74136
137void z80dart_ri_w(const device_config *device, int channel, int level);
138void z80dart_dcd_w(const device_config *device, int channel, int level);
139void z80dart_cts_w(const device_config *device, int channel, int level);
75140
76/* ----- device interface ----- */
141/***************************************************************************
142    READ/WRITE HANDLERS
143***************************************************************************/
77144
145/* A0 = B/A
146   A1 = C/D */
147READ8_DEVICE_HANDLER( z80dart_r );
148WRITE8_DEVICE_HANDLER( z80dart_w );
149
150/* A0 = C/D
151   A1 = B/A */
152READ8_DEVICE_HANDLER( z80dart_alt_r );
153WRITE8_DEVICE_HANDLER( z80dart_alt_w );
154
155/***************************************************************************
156    DEVICE INTERFACE
157***************************************************************************/
158
78159#define Z80DART DEVICE_GET_INFO_NAME(z80dart)
79160DEVICE_GET_INFO( z80dart );
80161
162#define Z8470 DEVICE_GET_INFO_NAME(z8470)
163DEVICE_GET_INFO( z8470 );
164
165#define LH0081 DEVICE_GET_INFO_NAME(lh0088)
166DEVICE_GET_INFO( lh0088 );
167
168#define MK3881 DEVICE_GET_INFO_NAME(mk3888)
169DEVICE_GET_INFO( mk3888 );
170
81171#endif
src/mess/machine/mtx.c
r3481r3482
265265   z80dart_c_w(device, offset, data);
266266}
267267
268const z80dart_interface mtx_dart_intf =
268Z80DART_INTERFACE( mtx_dart_intf )
269269{
270270      "main",
271271      MTX_SYSTEM_CLOCK,
272      0,
273      0,
274      0,
272275      NULL,
273276      NULL,
274277      NULL,
src/mess/drivers/abc80x.c
r3481r3482
171171
172172   if (keycode)
173173   {
174      if (!keylatch)
174      if (keycode != keylatch)
175175      {
176176         const device_config *z80dart = devtag_get_device(machine, Z80DART, Z80DART_TAG);
177177
178         z80dart_set_dcd(z80dart, 1, 1);
179         z80dart_receive_data(z80dart, 1, keycode);
178         z80dart_dcd_w(z80dart, Z80DART_CH_B, 0);
179         z80dart_receive_data(z80dart, Z80DART_CH_B, keycode);
180180
181181         keylatch = keycode;
182182      }
r3481r3482
187187      {
188188         const device_config *z80dart = devtag_get_device(machine, Z80DART, Z80DART_TAG);
189189
190         z80dart_set_dcd(z80dart, 1, 0);
191         z80dart_receive_data(z80dart, 1, 0);
190         z80dart_dcd_w(z80dart, Z80DART_CH_B, 1);
191         z80dart_receive_data(z80dart, Z80DART_CH_B, 0);
192192
193193         keylatch = 0;
194194      }
r3481r3482
208208{
209209}
210210
211// ABC 802
212
213static void abc802_bankswitch(running_machine *machine)
214{
215   abc802_state *state = machine->driver_data;
216
217   if (state->lrs)
218   {
219      /* ROM and video RAM selected */
220      memory_install_readwrite8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x77ff, 0, 0, SMH_BANK1, SMH_BANK1);
221      memory_install_readwrite8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x7800, 0x7fff, 0, 0, abc802_charram_r, abc802_charram_w);
222   }
223   else
224   {
225      /* low RAM selected */
226      memory_install_readwrite8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x7fff, 0, 0, SMH_BANK1, SMH_BANK1);
227   }
228
229   memory_set_bank(1, state->lrs);
230}
231
211232// ABC 806
212233
213234static void abc806_bankswitch(running_machine *machine)
r3481r3482
507528
508529static ADDRESS_MAP_START( abc802_map, ADDRESS_SPACE_PROGRAM, 8 )
509530   ADDRESS_MAP_UNMAP_HIGH
510   AM_RANGE(0x0000, 0x77ff) AM_RAMBANK(1)
511   AM_RANGE(0x7800, 0x7fff) AM_RAM AM_BASE(&videoram)
531   AM_RANGE(0x0000, 0x7fff) AM_RAMBANK(1)
512532   AM_RANGE(0x8000, 0xffff) AM_RAM
513533ADDRESS_MAP_END
514534
r3481r3482
723743
724744static ABC77_ON_CLOCK_CHANGED( abc77_clock_changed )
725745{
726//   const device_config *z80dart = devtag_get_device(device->machine, Z80DART, Z80DART_TAG);
746   const device_config *z80dart = devtag_get_device(device->machine, Z80DART, Z80DART_TAG);
727747
728   /* connected to DART channel B RxTxCB (pin ) */
729   //z80dart_rxtxc_w(z80dart, 1, level);
748   /* connected to DART channel B clock */
749   z80dart_rxtxcb_w(z80dart);
730750}
731751
732752static ABC77_ON_KEYDOWN_CHANGED( abc77_keydown_changed )
r3481r3482
734754   const device_config *z80dart = devtag_get_device(device->machine, Z80DART, Z80DART_TAG);
735755
736756   /* connected to DART channel B DCD (pin ) */
737   z80dart_set_dcd(z80dart, 1, level);
757   z80dart_dcd_w(z80dart, 1, level);
738758}
739759
740760static ABC77_INTERFACE( abc800_abc77_intf )
r3481r3482
795815
796816static WRITE8_DEVICE_HANDLER( ctc_z0_w )
797817{
798   //const device_config *z80sio = devtag_get_device(machine, Z80SIO, Z80SIO_TAG);
818   //const device_config *z80sio = devtag_get_device(device->machine, Z80SIO, Z80SIO_TAG);
799819
800820   UINT8 sb = input_port_read(device->machine, "SB");
801821
802822   if (BIT(sb, 2))
803823   {
804824      /* connected to SIO/2 TxCA, CTC CLK/TRG3 */
805      //z80sio_txc_w(z80sio, 0, data);
825      //z80sio_txca_w(z80sio, data);
806826      z80ctc_trg_w(device, 3, data);
807827   }
808828
809829   /* connected to SIO/2 RxCB through a thingy */
810830   //z80sio_rxcb = ?
811   //z80sio_rxc_w(z80sio, 1, z80sio_rxcb);
831   //z80sio_rxcb_w(z80sio, z80sio_rxcb);
812832
813833   /* connected to SIO/2 TxCB through a JK divide by 2 */
814834   //z80sio_txcb = !z80sio_txcb;
815   //z80sio_txc_w(z80sio, 1, z80sio_txcb);
835   //z80sio_txcb_w(z80sio, z80sio_txcb);
816836}
817837
818838static WRITE8_DEVICE_HANDLER( ctc_z1_w )
819839{
820   //const device_config *z80sio = devtag_get_device(machine, Z80SIO, Z80SIO_TAG);
840   //const device_config *z80sio = devtag_get_device(device->machine, Z80SIO, Z80SIO_TAG);
821841
822842   UINT8 sb = input_port_read(device->machine, "SB");
823843
824844   if (BIT(sb, 3))
825845   {
826846      /* connected to SIO/2 RxCA */
827      //z80sio_rxc_w(z80sio, 0, data);
847      //z80sio_rxca_w(z80sio, data);
828848   }
829849
830850   if (BIT(sb, 8))
831851   {
832852      /* connected to SIO/2 TxCA, CTC CLK/TRG3 */
833      //z80sio_txc_w(z80sio, 0, data);
853      //z80sio_txca_w(z80sio, data);
834854      z80ctc_trg_w(device, 3, data);
835855   }
836856}
837857
838858static WRITE8_DEVICE_HANDLER( ctc_z2_w )
839859{
840//   const device_config *z80dart = devtag_get_device(machine, Z80DART, Z80DART_TAG);
860   const device_config *z80dart = devtag_get_device(device->machine, Z80DART, Z80DART_TAG);
841861
842   /* connected to DART RxCA/TxCA (pin ) */
843   //z80dart_rxtxc_w(z80dart, 0, data);
862   /* connected to DART channel A clock inputs */
863   z80dart_rxca_w(z80dart);
864   z80dart_txca_w(z80dart);
844865}
845866
846867static const z80ctc_interface ctc_intf =
r3481r3482
902923
903924/* Z80 DART */
904925
905static WRITE8_DEVICE_HANDLER( dart_serial_transmit )
926static Z80DART_ON_INT_CHANGED( dart_interrupt )
906927{
928   cpunum_set_input_line(device->machine, 0, INPUT_LINE_IRQ0, state);
907929}
908930
909static int dart_serial_receive(const device_config *device, int ch)
931static Z80DART_RXD_READ( abc800_dart_rxd_r )
910932{
911   return -1;
933   abc800_state *state = device->machine->driver_data;
934
935   if (channel == Z80DART_CH_B)
936   {
937      /* receive bit from keyboard */
938      return state->abc77_txd;
939   }
940
941   return 1;
912942}
913943
914static void dart_interrupt(const device_config *device, int state)
944static Z80DART_ON_TXD_CHANGED( abc800_dart_txd_w )
915945{
916   cpunum_set_input_line(device->machine, 0, INPUT_LINE_IRQ0, state);
946   abc800_state *state = device->machine->driver_data;
947
948   if (channel == Z80DART_CH_B)
949   {
950      /* transmit bit to keyboard */
951      abc77_rxd_w(state->abc77, level);
952   }
917953}
918954
919static const z80dart_interface abc800_dart_intf =
955static Z80DART_INTERFACE( abc800_dart_intf )
920956{
921957   Z80_TAG,            /* cpu */
922958   ABC800_X01/2/2,         /* clock */
959   0,                  /* channel A receive clock */
960   0,                  /* channel A transmit clock */
961   0,                  /* channel B clock */
923962   dart_interrupt,         /* interrupt handler */
963   abc800_dart_rxd_r,      /* receive handler */
964   abc800_dart_txd_w,      /* transmit handler */
924965   0,                  /* DTR changed handler */
925966   0,                  /* RTS changed handler */
926   0,                  /* BREAK changed handler */
927   dart_serial_transmit,   /* transmit handler */
928   dart_serial_receive      /* receive handler */
967   0                  /* W/RDY changed handler */
929968};
930969
931static WRITE8_DEVICE_HANDLER( abc802_dart_dtr_w )
970static Z80DART_RXD_READ( abc802_dart_rxd_r )
932971{
933   if (offset == 1)
972   abc802_state *state = device->machine->driver_data;
973
974   if (channel == Z80DART_CH_B)
934975   {
935      /* _LRS */
936      memory_set_bank(1, data);
976      /* receive bit from keyboard */
977      return state->abc77_txd;
937978   }
979
980   return 1;
938981}
939982
940static WRITE8_DEVICE_HANDLER( abc802_dart_rts_w )
983static Z80DART_ON_TXD_CHANGED( abc802_dart_txd_w )
941984{
942985   abc802_state *state = device->machine->driver_data;
943986
944   if (offset == 1)
987   if (channel == Z80DART_CH_B)
945988   {
989      /* transmit bit to keyboard */
990      abc77_rxd_w(state->abc77, level);
991   }
992}
993
994static Z80DART_ON_DTR_CHANGED( abc802_dart_dtr_w )
995{
996   abc802_state *state = device->machine->driver_data;
997
998   if (channel == Z80DART_CH_B)
999   {
1000      /* low RAM select */
1001      state->lrs = level;
1002
1003      abc802_bankswitch(device->machine);
1004   }
1005}
1006
1007static Z80DART_ON_RTS_CHANGED( abc802_dart_rts_w )
1008{
1009   abc802_state *state = device->machine->driver_data;
1010
1011   if (channel == Z80DART_CH_B)
1012   {
9461013      /* _MUX 80/40 */
947      state->mux80_40 = !BIT(data, 0);
1014      state->mux80_40 = level;
9481015   }
9491016}
9501017
951static const z80dart_interface abc802_dart_intf =
1018static Z80DART_INTERFACE( abc802_dart_intf )
9521019{
9531020   Z80_TAG,            /* cpu */
9541021   ABC800_X01/2/2,         /* clock */
955   0,                  /* interrupt handler */
1022   0,                  /* channel A receive clock */
1023   0,                  /* channel A transmit clock */
1024   0,                  /* channel B clock */
1025   dart_interrupt,         /* interrupt handler */
1026   abc802_dart_rxd_r,      /* receive handler */
1027   abc802_dart_txd_w,      /* transmit handler */
9561028   abc802_dart_dtr_w,      /* DTR changed handler */
9571029   abc802_dart_rts_w,      /* RTS changed handler */
958   0,                  /* BREAK changed handler */
959   dart_serial_transmit,   /* transmit handler */
960   dart_serial_receive      /* receive handler */
1030   0                  /* W/RDY changed handler */
9611031};
9621032
963static WRITE8_DEVICE_HANDLER( abc806_dart_dtr_w )
1033static Z80DART_RXD_READ( abc806_dart_rxd_r )
9641034{
9651035   abc806_state *state = device->machine->driver_data;
1036
1037   if (channel == Z80DART_CH_B)
1038   {
1039      /* receive bit from keyboard */
1040      return state->abc77_txd;
1041   }
1042
1043   return 1;
1044}
1045
1046static Z80DART_ON_TXD_CHANGED( abc806_dart_txd_w )
1047{
1048   abc806_state *state = device->machine->driver_data;
1049
1050   if (channel == Z80DART_CH_B)
1051   {
1052      /* transmit bit to keyboard */
1053      abc77_rxd_w(state->abc77, level);
1054   }
1055}
1056
1057static Z80DART_ON_DTR_CHANGED( abc806_dart_dtr_w )
1058{
1059   abc806_state *state = device->machine->driver_data;
9661060   
967   if (offset == 1)
1061   if (channel == Z80DART_CH_B)
9681062   {
969      state->keydtr = BIT(data, 0);
1063      state->keydtr = level;
9701064   }
9711065}
9721066
973static const z80dart_interface abc806_dart_intf =
1067static Z80DART_INTERFACE( abc806_dart_intf )
9741068{
9751069   Z80_TAG,            /* cpu */
9761070   ABC800_X01/2/2,         /* clock */
977   0,                  /* interrupt handler */
1071   0,                  /* channel A receive clock */
1072   0,                  /* channel A transmit clock */
1073   0,                  /* channel B clock */
1074   dart_interrupt,         /* interrupt handler */
1075   abc806_dart_rxd_r,      /* receive handler */
1076   abc806_dart_txd_w,      /* transmit handler */
9781077   abc806_dart_dtr_w,      /* DTR changed handler */
9791078   0,                  /* RTS changed handler */
980   0,                  /* BREAK changed handler */
981   dart_serial_transmit,   /* transmit handler */
982   dart_serial_receive      /* receive handler */
1079   0                  /* W/RDY changed handler */
9831080};
9841081
9851082/* E05-16 */
r3481r3482
10261123
10271124   /* configure memory */
10281125
1029   memory_configure_bank(1, 0, 1, memory_region(machine, Z80_TAG), 0);
1030   memory_configure_bank(1, 1, 1, mess_ram, 0);
1126   memory_configure_bank(1, 0, 1, mess_ram, 0);
1127   memory_configure_bank(1, 1, 1, memory_region(machine, Z80_TAG), 0);
10311128}
10321129
10331130static MACHINE_RESET( abc802 )
r3481r3482
10351132   abc802_state *state = machine->driver_data;
10361133
10371134   /* memory banking */
1038   memory_set_bank(1, 0);
1135   memory_set_bank(1, 1);
10391136
10401137   /* clear screen time out (S1) */
10411138   z80sio_set_dcd(state->z80sio, 1, 0);
r3481r3482
10441141   z80sio_set_cts(state->z80sio, 1, 0);
10451142
10461143   /* 40/80 char (S3) */
1047   z80dart_set_ri(state->z80dart, 0, 0); // 0 = 40, 1 = 80
1144   z80dart_ri_w(state->z80dart, Z80DART_CH_A, 1); // 0 = 40, 1 = 80
10481145
10491146   /* 50/60 Hz */
1050   z80dart_set_cts(state->z80dart, 1, 0); // 0 = 50Hz, 1 = 60Hz ???
1147   z80dart_cts_w(state->z80dart, Z80DART_CH_B, 0); // 0 = 50Hz, 1 = 60Hz ???
10511148}
10521149
10531150static MACHINE_START( abc806 )
r3481r3482
14891586   return address;
14901587}
14911588
1589static OPBASE_HANDLER( abc802_opbase_handler )
1590{
1591   abc802_state *state = machine->driver_data;
1592
1593   if (state->lrs)
1594   {
1595      if (address >= 0x7800 && address < 0x8000)
1596      {
1597         opbase->rom = opbase->ram = memory_region(machine, Z80_TAG);
1598         return ~0;
1599      }
1600   }
1601   else
1602   {
1603      opbase->rom = opbase->ram = mess_ram;
1604      return ~0;
1605   }
1606
1607   return address;
1608}
1609
14921610static OPBASE_HANDLER( abc806_opbase_handler )
14931611{
14941612   abc806_state *state = machine->driver_data;
r3481r3482
15201638   memory_set_opbase_handler(0, abc800_opbase_handler);
15211639}
15221640
1641static DRIVER_INIT( abc802 )
1642{
1643   memory_set_opbase_handler(0, abc802_opbase_handler);
1644}
1645
15231646static DRIVER_INIT( abc806 )
15241647{
15251648   memory_set_opbase_handler(0, abc806_opbase_handler);
r3481r3482
15301653/*    YEAR  NAME        PARENT      COMPAT  MACHINE     INPUT   INIT    CONFIG  COMPANY             FULLNAME    FLAGS */
15311654COMP( 1981, abc800m,    0,         0,      abc800m,    abc800, abc800, abc800, "Luxor Datorer AB", "ABC 800 M", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
15321655COMP( 1981, abc800c,    abc800m,    0,      abc800c,    abc800, abc800, abc800, "Luxor Datorer AB", "ABC 800 C", GAME_NOT_WORKING )
1533COMP( 1983, abc802,     0,          0,      abc802,     abc802, abc800, abc802, "Luxor Datorer AB", "ABC 802",  GAME_NOT_WORKING )
1534COMP( 1983, abc806,     0,          0,      abc806,     abc806, abc806, abc806, "Luxor Datorer AB", "ABC 806",  GAME_NOT_WORKING )
1656COMP( 1983, abc802,     0,          0,      abc802,     abc802, abc802, abc802, "Luxor Datorer AB", "ABC 802",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
1657COMP( 1983, abc806,     0,          0,      abc806,     abc806, abc806, abc806, "Luxor Datorer AB", "ABC 806",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team