Previous 15994 Revisions Next

r4947 Friday 5th June, 2009 at 22:25:13 UTC by Curt Coder
[Z80STI] Added some meat on the bones.
[src/mess/machine]z80sti.c z80sti.h

src/mess/machine/z80sti.c
r4946r4947
22
33    Mostek Z80STI Serial Timer Interrupt Controller emulation
44
5    Copyright (c) 2008, The MESS Team.
5    Copyright (c) 2009, The MESS Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
88***************************************************************************/
r4946r4947
4848   Z80STI_REGISTER_UDR
4949};
5050
51enum
52{
53   Z80STI_TIMER_A = 0,
54   Z80STI_TIMER_B,
55   Z80STI_TIMER_C,
56   Z80STI_TIMER_D,
57   Z80STI_MAX_TIMERS
58};
59
5160/***************************************************************************
5261    TYPE DEFINITIONS
5362***************************************************************************/
r4946r4947
6372   devcb_resolved_write_line   out_tbo_func;
6473   devcb_resolved_write_line   out_tco_func;
6574   devcb_resolved_write_line   out_tdo_func;
66   devcb_resolved_write_line   out_irq_func;
75   devcb_resolved_write_line   out_int_func;
76
77   /* I/O state */
78   UINT8 gpip;                     /* general purpose I/O register */
79   UINT8 aer;                     /* active edge register */
80   UINT8 ddr;                     /* data direction register */
81
82   /* interrupt state */
83   UINT16 ier;                     /* interrupt enable register */
84   UINT16 ipr;                     /* interrupt pending register */
85   UINT16 isr;                     /* interrupt in-service register */
86   UINT16 imr;                     /* interrupt mask register */
87   UINT8 pvr;                     /*  */
88
89   /* timer state */
90   UINT8 tabc;                     /*  */
91   UINT8 tcdc;                     /*  */
92   UINT8 tdr[Z80STI_MAX_TIMERS];      /* timer data registers */
93   UINT8 tmc[Z80STI_MAX_TIMERS];      /* timer main counters */
94
95   /* serial state */
96   UINT8 scr;                     /* synchronous character register */
97   UINT8 ucr;                     /* USART control register */
98   UINT8 tsr;                     /* transmitter status register */
99   UINT8 rsr;                     /* receiver status register */
100   UINT8 udr;                     /* USART data register */
101
102   /* timers */
103   emu_timer *timer[Z80STI_MAX_TIMERS];   /* counter timers */
104   emu_timer *rx_timer;               /* serial receive timer */
105   emu_timer *tx_timer;               /* serial transmit timer */
67106};
68107
69108/***************************************************************************
r4946r4947
97136***************************************************************************/
98137
99138/*-------------------------------------------------
139    check_interrupts - set the interrupt request
140   line state
141-------------------------------------------------*/
142#ifdef UNUSED_CODE
143static void check_interrupts(const device_config *device)
144{
145   z80sti_t *z80sti = get_safe_token(device);
146
147   if (z80sti->ipr & z80sti->imr)
148   {
149      devcb_call_write_line(&z80sti->out_int_func, ASSERT_LINE);
150   }
151   else
152   {
153      devcb_call_write_line(&z80sti->out_int_func, CLEAR_LINE);
154   }
155}
156
157/*-------------------------------------------------
158    take_interrupt - mark an interrupt pending
159-------------------------------------------------*/
160
161static void take_interrupt(const device_config *device, UINT16 mask)
162{
163   z80sti_t *z80sti = get_safe_token(device);
164
165   z80sti->ipr |= mask;
166
167   check_interrupts(device);
168}
169#endif
170/*-------------------------------------------------
171    serial_receive - receive serial bit
172-------------------------------------------------*/
173
174static void serial_receive(z80sti_t *z80sti)
175{
176}
177
178/*-------------------------------------------------
179    TIMER_CALLBACK( rx_tick )
180-------------------------------------------------*/
181
182static TIMER_CALLBACK( rx_tick )
183{
184   const device_config *device = ptr;
185   z80sti_t *z80sti = get_safe_token(device);
186
187   serial_receive(z80sti);
188}
189
190/*-------------------------------------------------
191    serial_transmit - transmit serial bit
192-------------------------------------------------*/
193
194static void serial_transmit(z80sti_t *z80sti)
195{
196}
197
198/*-------------------------------------------------
199    TIMER_CALLBACK( tx_tick )
200-------------------------------------------------*/
201
202static TIMER_CALLBACK( tx_tick )
203{
204   const device_config *device = ptr;
205   z80sti_t *z80sti = get_safe_token(device);
206
207   serial_transmit(z80sti);
208}
209
210/*-------------------------------------------------
100211    z80sti_r - register read
101212-------------------------------------------------*/
102213
r4946r4947
119230
120231WRITE_LINE_DEVICE_HANDLER( z80sti_rc_w )
121232{
233   z80sti_t *z80sti = get_safe_token(device);
234
235   if (state)
236   {
237      serial_receive(z80sti);
238   }
122239}
123240
124241/*-------------------------------------------------
r4946r4947
127244
128245WRITE_LINE_DEVICE_HANDLER( z80sti_tc_w )
129246{
247   z80sti_t *z80sti = get_safe_token(device);
248
249   if (state)
250   {
251      serial_transmit(z80sti);
252   }
130253}
131254
132255/*-------------------------------------------------
256    timer_count - timer count down
257-------------------------------------------------*/
258
259static void timer_count(z80sti_t *z80sti, int index)
260{
261}
262
263/*-------------------------------------------------
264    TIMER_CALLBACK( timer_a )
265-------------------------------------------------*/
266
267static TIMER_CALLBACK( timer_a ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_A); }
268static TIMER_CALLBACK( timer_b ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_B); }
269static TIMER_CALLBACK( timer_c ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_C); }
270static TIMER_CALLBACK( timer_d ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_D); }
271
272/*-------------------------------------------------
133273    z80sti_i0_w - input 0 write
134274-------------------------------------------------*/
135275
r4946r4947
237377   devcb_resolve_write_line(&z80sti->out_tbo_func, &intf->out_tbo_func, device);
238378   devcb_resolve_write_line(&z80sti->out_tco_func, &intf->out_tco_func, device);
239379   devcb_resolve_write_line(&z80sti->out_tdo_func, &intf->out_tdo_func, device);
240   devcb_resolve_write_line(&z80sti->out_irq_func, &intf->out_irq_func, device);
380   devcb_resolve_write_line(&z80sti->out_int_func, &intf->out_int_func, device);
381
382   /* create the counter timers */
383   z80sti->timer[Z80STI_TIMER_A] = timer_alloc(device->machine, timer_a, (void *)device);
384   z80sti->timer[Z80STI_TIMER_B] = timer_alloc(device->machine, timer_b, (void *)device);
385   z80sti->timer[Z80STI_TIMER_C] = timer_alloc(device->machine, timer_c, (void *)device);
386   z80sti->timer[Z80STI_TIMER_D] = timer_alloc(device->machine, timer_d, (void *)device);
387
388   /* create serial receive clock timer */
389   if (intf->rx_clock > 0)
390   {
391      z80sti->rx_timer = timer_alloc(device->machine, rx_tick, (void *)device);
392      timer_adjust_periodic(z80sti->rx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(intf->rx_clock));
393   }
394
395   /* create serial transmit clock timer */
396   if (intf->tx_clock > 0)
397   {
398      z80sti->tx_timer = timer_alloc(device->machine, tx_tick, (void *)device);
399      timer_adjust_periodic(z80sti->tx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(intf->tx_clock));
400   }
401
402   /* register for state saving */
403   state_save_register_device_item(device, 0, z80sti->gpip);
404   state_save_register_device_item(device, 0, z80sti->aer);
405   state_save_register_device_item(device, 0, z80sti->ddr);
406   state_save_register_device_item(device, 0, z80sti->ier);
407   state_save_register_device_item(device, 0, z80sti->ipr);
408   state_save_register_device_item(device, 0, z80sti->isr);
409   state_save_register_device_item(device, 0, z80sti->imr);
410   state_save_register_device_item(device, 0, z80sti->pvr);
411   state_save_register_device_item(device, 0, z80sti->tabc);
412   state_save_register_device_item(device, 0, z80sti->tcdc);
413   state_save_register_device_item_array(device, 0, z80sti->tdr);
414   state_save_register_device_item_array(device, 0, z80sti->tmc);
415   state_save_register_device_item(device, 0, z80sti->scr);
416   state_save_register_device_item(device, 0, z80sti->ucr);
417   state_save_register_device_item(device, 0, z80sti->rsr);
418   state_save_register_device_item(device, 0, z80sti->tsr);
419   state_save_register_device_item(device, 0, z80sti->udr);
241420}
242421
243422/*-------------------------------------------------
src/mess/machine/z80sti.h
r4946r4947
4646   MDRV_DEVICE_ADD((_tag), Z80STI, _clock)   \
4747   MDRV_DEVICE_CONFIG(_config)
4848
49#define MDRV_MK68901_ADD(_tag, _clock, _config) \
50   MDRV_DEVICE_ADD((_tag), MK68901, _clock)   \
51   MDRV_DEVICE_CONFIG(_config)
52
5349#define Z80STI_INTERFACE(name) const z80sti_interface (name) =
5450
5551/***************************************************************************
r4946r4947
6258   int   rx_clock;         /* serial receive clock */
6359   int   tx_clock;         /* serial transmit clock */
6460
65   /* this is called on each read of the I/O pins */
61   /* this is called on each read of the GPIO pins */
6662   devcb_read8            in_gpio_func;
6763
68   /* this is called on each write of the I/O pins */
64   /* this is called on each write of the GPIO pins */
6965   devcb_write8         out_gpio_func;
7066
7167   /* this gets called for each read of the SI pin (pin 38) */
r4946r4947
8783   devcb_write_line      out_tdo_func;
8884
8985   /* this gets called on each change of the interrupt line (pin 17) */
90   devcb_write_line      out_irq_func;
86   devcb_write_line      out_int_func;
9187};
9288
9389/***************************************************************************

Previous 15994 Revisions Next


© 1998-2018 The MESS Team