Previous 199869 Revisions Next

r18805 Thursday 1st November, 2012 at 19:24:29 UTC by smf
split psx sio into two devices (nw)
[src/emu/cpu/psx]psx.c sio.c sio.h

trunk/src/emu/cpu/psx/psx.c
r18804r18805
15321532   /* 1f801018 dv delay */
15331533   AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w )
15341534   AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM
1535   AM_RANGE(0x1f801040, 0x1f80105f) AM_DEVREADWRITE( "sio", psxsio_device, read, write )
1535   AM_RANGE(0x1f801040, 0x1f80104f) AM_DEVREADWRITE( "sio0", psxsio_device, read, write )
1536   AM_RANGE(0x1f801050, 0x1f80105f) AM_DEVREADWRITE( "sio1", psxsio_device, read, write )
15361537   /* 1f801060 ram config */
15371538   AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM
15381539   AM_RANGE(0x1f801070, 0x1f801077) AM_DEVREADWRITE( "irq", psxirq_device, read, write )
r18804r18805
15601561   AM_RANGE(0x1f801000, 0x1f80101f) AM_RAM
15611562   AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w )
15621563   AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM
1563   AM_RANGE(0x1f801040, 0x1f80105f) AM_DEVREADWRITE( "sio", psxsio_device, read, write )
1564   AM_RANGE(0x1f801040, 0x1f80104f) AM_DEVREADWRITE( "sio0", psxsio_device, read, write )
1565   AM_RANGE(0x1f801050, 0x1f80105f) AM_DEVREADWRITE( "sio1", psxsio_device, read, write )
15641566   AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM
15651567   AM_RANGE(0x1f801070, 0x1f801077) AM_DEVREADWRITE( "irq", psxirq_device, read, write )
15661568   AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE( "dma", psxdma_device, read, write )
r18804r18805
31673169
31683170void psxcpu_device::install_sio_handler( device_t &device, const char *cputag, int n_port, psx_sio_handler p_f_sio_handler )
31693171{
3170   psxsio_device *sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio");
3171   sio->install_handler( n_port, p_f_sio_handler );
3172   psxsio_device *sio;
3173
3174   switch( n_port )
3175   {
3176   case 0:
3177      sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio0");
3178      break;
3179   case 1:
3180      sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio1");
3181      break;
3182   default:
3183      return;
3184   }
3185
3186   sio->install_handler( p_f_sio_handler );
31723187}
31733188
31743189void psxcpu_device::sio_input( device_t &device, const char *cputag, int n_port, int n_mask, int n_data )
31753190{
3176   psxsio_device *sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio");
3177   sio->input( n_port, n_mask, n_data );
3191   psxsio_device *sio;
3192
3193   switch( n_port )
3194   {
3195   case 0:
3196      sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio0");
3197      break;
3198   case 1:
3199      sio = getcpu( device, cputag )->subdevice<psxsio_device>("sio1");
3200      break;
3201   default:
3202      return;
3203   }
3204
3205   sio->input( n_mask, n_data );
31783206}
31793207
31803208READ32_HANDLER( psxcpu_device::gpu_r )
r18804r18805
32033231   MCFG_PSX_RCNT_IRQ1_HANDLER(DEVWRITELINE("irq", psxirq_device, intin5))
32043232   MCFG_PSX_RCNT_IRQ2_HANDLER(DEVWRITELINE("irq", psxirq_device, intin6))
32053233
3206   MCFG_DEVICE_ADD("sio", PSX_SIO, 0)
3207   MCFG_PSX_SIO_IRQ0_HANDLER(DEVWRITELINE("irq", psxirq_device, intin7))
3208   MCFG_PSX_SIO_IRQ1_HANDLER(DEVWRITELINE("irq", psxirq_device, intin8))
3234   MCFG_DEVICE_ADD("sio0", PSX_SIO0, 0)
3235   MCFG_PSX_SIO_IRQ_HANDLER(DEVWRITELINE("irq", psxirq_device, intin7))
3236
3237   MCFG_DEVICE_ADD("sio1", PSX_SIO1, 0)
3238   MCFG_PSX_SIO_IRQ_HANDLER(DEVWRITELINE("irq", psxirq_device, intin8))
32093239MACHINE_CONFIG_END
32103240
32113241//-------------------------------------------------
trunk/src/emu/cpu/psx/sio.c
r18804r18805
2323   }
2424}
2525
26const device_type PSX_SIO = &device_creator<psxsio_device>;
26const device_type PSX_SIO0 = &device_creator<psxsio0_device>;
27const device_type PSX_SIO1 = &device_creator<psxsio1_device>;
2728
28psxsio_device::psxsio_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
29   device_t(mconfig, PSX_SIO, "PSX SIO", tag, owner, clock),
30   m_irq0_handler(*this),
31   m_irq1_handler(*this)
29psxsio0_device::psxsio0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
30   psxsio_device(mconfig, PSX_SIO0, tag, owner, clock)
3231{
33   int n;
32}
3433
35   for( n = 0; n < 2; n++ )
36   {
37      port[ n ].fn_handler = NULL;
38   }
34psxsio1_device::psxsio1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
35   psxsio_device(mconfig, PSX_SIO1, tag, owner, clock)
36{
3937}
4038
41void psxsio_device::device_reset()
39psxsio_device::psxsio_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock) :
40   device_t(mconfig, type, "PSX SIO", tag, owner, clock),
41   m_fn_handler(NULL),
42   m_irq_handler(*this)
4243{
4344}
4445
4546void psxsio_device::device_post_load()
4647{
47   int n;
48
49   for( n = 0; n < 2; n++ )
50   {
51      sio_timer_adjust( n );
52   }
48   sio_timer_adjust();
5349}
5450
5551void psxsio_device::device_start()
5652{
57   int n;
53   m_irq_handler.resolve_safe();
5854
59   m_irq0_handler.resolve_safe();
60   m_irq1_handler.resolve_safe();
55   m_timer = timer_alloc( 0 );
56   m_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY;
57   m_mode = 0;
58   m_control = 0;
59   m_baud = 0;
60   m_tx = 0;
61   m_rx = 0;
62   m_tx_prev = 0;
63   m_rx_prev = 0;
64   m_rx_data = 0;
65   m_tx_data = 0;
66   m_rx_shift = 0;
67   m_tx_shift = 0;
68   m_rx_bits = 0;
69   m_tx_bits = 0;
6170
62   for( n = 0; n < 2; n++ )
63   {
64      port[ n ].timer = machine().scheduler().timer_alloc( timer_expired_delegate( FUNC( psxsio_device::sio_clock ), this ) );
65      port[ n ].n_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY;
66      port[ n ].n_mode = 0;
67      port[ n ].n_control = 0;
68      port[ n ].n_baud = 0;
69      port[ n ].n_tx = 0;
70      port[ n ].n_rx = 0;
71      port[ n ].n_tx_prev = 0;
72      port[ n ].n_rx_prev = 0;
73      port[ n ].n_rx_data = 0;
74      port[ n ].n_tx_data = 0;
75      port[ n ].n_rx_shift = 0;
76      port[ n ].n_tx_shift = 0;
77      port[ n ].n_rx_bits = 0;
78      port[ n ].n_tx_bits = 0;
79   }
80
81   for( n = 0; n < 2; n++ )
82   {
83      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_status );
84      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_mode );
85      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_control );
86      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_baud );
87      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx );
88      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx );
89      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_prev );
90      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_prev );
91      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_data );
92      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_data );
93      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_shift );
94      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_shift );
95      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_rx_bits );
96      state_save_register_item( machine(), "psxsio", NULL, n, port[n].n_tx_bits );
97   }
71   save_item( NAME( m_status ) );
72   save_item( NAME( m_mode ) );
73   save_item( NAME( m_control ) );
74   save_item( NAME( m_baud ) );
75   save_item( NAME( m_tx ) );
76   save_item( NAME( m_rx ) );
77   save_item( NAME( m_tx_prev ) );
78   save_item( NAME( m_rx_prev ) );
79   save_item( NAME( m_rx_data ) );
80   save_item( NAME( m_tx_data ) );
81   save_item( NAME( m_rx_shift ) );
82   save_item( NAME( m_tx_shift ) );
83   save_item( NAME( m_rx_bits ) );
84   save_item( NAME( m_tx_bits ) );
9885}
9986
100void psxsio_device::install_handler( int n_port, psx_sio_handler p_f_sio_handler )
87void psxsio_device::install_handler( psx_sio_handler p_f_sio_handler )
10188{
102   port[ n_port ].fn_handler = p_f_sio_handler;
89   m_fn_handler = p_f_sio_handler;
10390}
10491
105void psxsio_device::sio_interrupt( int n_port )
92void psxsio_device::sio_interrupt()
10693{
107   psx_sio *sio = &port[ n_port ];
108
109   verboselog( machine(), 1, "sio_interrupt( %d )\n", n_port );
110   sio->n_status |= SIO_STATUS_IRQ;
111   if( n_port == 0 )
112   {
113      m_irq0_handler(1);
114   }
115   else
116   {
117      m_irq1_handler(1);
118   }
94   verboselog( machine(), 1, "sio_interrupt( %s )\n", tag() );
95   m_status |= SIO_STATUS_IRQ;
96   m_irq_handler(1);
11997}
12098
121void psxsio_device::sio_timer_adjust( int n_port )
99void psxsio_device::sio_timer_adjust()
122100{
123   psx_sio *sio = &port[ n_port ];
124101   attotime n_time;
125102
126   if( ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 || sio->n_tx_bits != 0 )
103   if( ( m_status & SIO_STATUS_TX_EMPTY ) == 0 || m_tx_bits != 0 )
127104   {
128105      int n_prescaler;
129106
130      switch( sio->n_mode & 3 )
107      switch( m_mode & 3 )
131108      {
132109      case 1:
133110         n_prescaler = 1;
r18804r18805
143120         break;
144121      }
145122
146      if( sio->n_baud != 0 && n_prescaler != 0 )
123      if( m_baud != 0 && n_prescaler != 0 )
147124      {
148         n_time = attotime::from_hz(33868800) * (n_prescaler * sio->n_baud);
149         verboselog( machine(), 2, "sio_timer_adjust( %d ) = %s ( %d x %d )\n", n_port, n_time.as_string(), n_prescaler, sio->n_baud );
125         n_time = attotime::from_hz(33868800) * (n_prescaler * m_baud);
126         verboselog( machine(), 2, "sio_timer_adjust( %s ) = %s ( %d x %d )\n", tag(), n_time.as_string(), n_prescaler, m_baud );
150127      }
151128      else
152129      {
153130         n_time = attotime::never;
154         verboselog( machine(), 0, "sio_timer_adjust( %d ) invalid baud rate ( %d x %d )\n", n_port, n_prescaler, sio->n_baud );
131         verboselog( machine(), 0, "sio_timer_adjust( %s ) invalid baud rate ( %d x %d )\n", tag(), n_prescaler, m_baud );
155132      }
156133   }
157134   else
158135   {
159136      n_time = attotime::never;
160      verboselog( machine(), 2, "sio_timer_adjust( %d ) finished\n", n_port );
137      verboselog( machine(), 2, "sio_timer_adjust( %s ) finished\n", tag() );
161138   }
162   sio->timer->adjust( n_time, n_port);
139
140   m_timer->adjust( n_time );
163141}
164142
165TIMER_CALLBACK_MEMBER(psxsio_device::sio_clock)
143void psxsio_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
166144{
167   int n_port = param;
168   psx_sio *sio = &port[ n_port ];
169145   verboselog( machine(), 2, "sio tick\n" );
170146
171   if( sio->n_tx_bits == 0 &&
172      ( sio->n_control & SIO_CONTROL_TX_ENA ) != 0 &&
173      ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 )
147   if( m_tx_bits == 0 &&
148      ( m_control & SIO_CONTROL_TX_ENA ) != 0 &&
149      ( m_status & SIO_STATUS_TX_EMPTY ) == 0 )
174150   {
175      sio->n_tx_bits = 8;
176      sio->n_tx_shift = sio->n_tx_data;
177      if( n_port == 0 )
151      m_tx_bits = 8;
152      m_tx_shift = m_tx_data;
153
154      if( type() == PSX_SIO0 )
178155      {
179         sio->n_rx_bits = 8;
180         sio->n_rx_shift = 0;
156         m_rx_bits = 8;
157         m_rx_shift = 0;
181158      }
182      sio->n_status |= SIO_STATUS_TX_EMPTY;
183      sio->n_status |= SIO_STATUS_TX_RDY;
159
160      m_status |= SIO_STATUS_TX_EMPTY;
161      m_status |= SIO_STATUS_TX_RDY;
184162   }
185163
186   if( sio->n_tx_bits != 0 )
164   if( m_tx_bits != 0 )
187165   {
188      sio->n_tx = ( sio->n_tx & ~PSX_SIO_OUT_DATA ) | ( ( sio->n_tx_shift & 1 ) * PSX_SIO_OUT_DATA );
189      sio->n_tx_shift >>= 1;
190      sio->n_tx_bits--;
166      m_tx = ( m_tx & ~PSX_SIO_OUT_DATA ) | ( ( m_tx_shift & 1 ) * PSX_SIO_OUT_DATA );
167      m_tx_shift >>= 1;
168      m_tx_bits--;
191169
192      if( sio->fn_handler != NULL )
170      if( m_fn_handler != NULL )
193171      {
194         if( n_port == 0 )
172         if( type() == PSX_SIO0 )
195173         {
196            sio->n_tx &= ~PSX_SIO_OUT_CLOCK;
197            (*sio->fn_handler)( machine(), sio->n_tx );
198            sio->n_tx |= PSX_SIO_OUT_CLOCK;
174            m_tx &= ~PSX_SIO_OUT_CLOCK;
175            (*m_fn_handler)( machine(), m_tx );
176            m_tx |= PSX_SIO_OUT_CLOCK;
199177         }
200         (*sio->fn_handler)( machine(), sio->n_tx );
178
179         (*m_fn_handler)( machine(), m_tx );
201180      }
202181
203      if( sio->n_tx_bits == 0 &&
204         ( sio->n_control & SIO_CONTROL_TX_IENA ) != 0 )
182      if( m_tx_bits == 0 &&
183         ( m_control & SIO_CONTROL_TX_IENA ) != 0 )
205184      {
206         sio_interrupt( n_port );
185         sio_interrupt();
207186      }
208187   }
209188
210   if( sio->n_rx_bits != 0 )
189   if( m_rx_bits != 0 )
211190   {
212      sio->n_rx_shift = ( sio->n_rx_shift >> 1 ) | ( ( ( sio->n_rx & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 );
213      sio->n_rx_bits--;
191      m_rx_shift = ( m_rx_shift >> 1 ) | ( ( ( m_rx & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 );
192      m_rx_bits--;
214193
215      if( sio->n_rx_bits == 0 )
194      if( m_rx_bits == 0 )
216195      {
217         if( ( sio->n_status & SIO_STATUS_RX_RDY ) != 0 )
196         if( ( m_status & SIO_STATUS_RX_RDY ) != 0 )
218197         {
219            sio->n_status |= SIO_STATUS_OVERRUN;
198            m_status |= SIO_STATUS_OVERRUN;
220199         }
221200         else
222201         {
223            sio->n_rx_data = sio->n_rx_shift;
224            sio->n_status |= SIO_STATUS_RX_RDY;
202            m_rx_data = m_rx_shift;
203            m_status |= SIO_STATUS_RX_RDY;
225204         }
226         if( ( sio->n_control & SIO_CONTROL_RX_IENA ) != 0 )
205
206         if( ( m_control & SIO_CONTROL_RX_IENA ) != 0 )
227207         {
228            sio_interrupt( n_port );
208            sio_interrupt();
229209         }
230210      }
231211   }
232212
233   sio_timer_adjust( n_port );
213   sio_timer_adjust();
234214}
235215
236216WRITE32_MEMBER( psxsio_device::write )
237217{
238   int n_port = offset / 4;
239   psx_sio *sio = &port[ n_port ];
240
241218   switch( offset % 4 )
242219   {
243220   case 0:
244      verboselog( machine(), 1, "psx_sio_w %d data %02x (%08x)\n", n_port, data, mem_mask );
245      sio->n_tx_data = data;
246      sio->n_status &= ~( SIO_STATUS_TX_RDY );
247      sio->n_status &= ~( SIO_STATUS_TX_EMPTY );
248      sio_timer_adjust( n_port );
221      verboselog( machine(), 1, "psx_sio_w %s data %02x (%08x)\n", tag(), data, mem_mask );
222      m_tx_data = data;
223      m_status &= ~( SIO_STATUS_TX_RDY );
224      m_status &= ~( SIO_STATUS_TX_EMPTY );
225      sio_timer_adjust();
249226      break;
250227   case 1:
251228      verboselog( machine(), 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask );
r18804r18805
253230   case 2:
254231      if( ACCESSING_BITS_0_15 )
255232      {
256         sio->n_mode = data & 0xffff;
257         verboselog( machine(), 1, "psx_sio_w %d mode %04x\n", n_port, data & 0xffff );
233         m_mode = data & 0xffff;
234         verboselog( machine(), 1, "psx_sio_w %s mode %04x\n", tag(), data & 0xffff );
258235      }
259236      if( ACCESSING_BITS_16_31 )
260237      {
261         verboselog( machine(), 1, "psx_sio_w %d control %04x\n", n_port, data >> 16 );
262         sio->n_control = data >> 16;
238         verboselog( machine(), 1, "psx_sio_w %s control %04x\n", tag(), data >> 16 );
239         m_control = data >> 16;
263240
264         if( ( sio->n_control & SIO_CONTROL_RESET ) != 0 )
241         if( ( m_control & SIO_CONTROL_RESET ) != 0 )
265242         {
266243            verboselog( machine(), 1, "psx_sio_w reset\n" );
267            sio->n_status |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY;
268            sio->n_status &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ );
244            m_status |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY;
245            m_status &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ );
269246         }
270         if( ( sio->n_control & SIO_CONTROL_IACK ) != 0 )
247         if( ( m_control & SIO_CONTROL_IACK ) != 0 )
271248         {
272249            verboselog( machine(), 1, "psx_sio_w iack\n" );
273            sio->n_status &= ~( SIO_STATUS_IRQ );
274            sio->n_control &= ~( SIO_CONTROL_IACK );
250            m_status &= ~( SIO_STATUS_IRQ );
251            m_control &= ~( SIO_CONTROL_IACK );
275252         }
276         if( ( sio->n_control & SIO_CONTROL_DTR ) != 0 )
253         if( ( m_control & SIO_CONTROL_DTR ) != 0 )
277254         {
278            sio->n_tx |= PSX_SIO_OUT_DTR;
255            m_tx |= PSX_SIO_OUT_DTR;
279256         }
280257         else
281258         {
282            sio->n_tx &= ~PSX_SIO_OUT_DTR;
259            m_tx &= ~PSX_SIO_OUT_DTR;
283260         }
284261
285         if( ( ( sio->n_tx ^ sio->n_tx_prev ) & PSX_SIO_OUT_DTR ) != 0 )
262         if( ( ( m_tx ^ m_tx_prev ) & PSX_SIO_OUT_DTR ) != 0 )
286263         {
287            if( sio->fn_handler != NULL )
264            if( m_fn_handler != NULL )
288265            {
289               (*sio->fn_handler)( machine(), sio->n_tx );
266               (*m_fn_handler)( machine(), m_tx );
290267            }
291268         }
292         sio->n_tx_prev = sio->n_tx;
293269
270         m_tx_prev = m_tx;
271
294272      }
295273      break;
296274   case 3:
r18804r18805
300278      }
301279      if( ACCESSING_BITS_16_31 )
302280      {
303         sio->n_baud = data >> 16;
304         verboselog( machine(), 1, "psx_sio_w %d baud %04x\n", n_port, data >> 16 );
281         m_baud = data >> 16;
282         verboselog( machine(), 1, "psx_sio_w %s baud %04x\n", tag(), data >> 16 );
305283      }
306284      break;
307285   default:
r18804r18805
312290
313291READ32_MEMBER( psxsio_device::read )
314292{
315   int n_port = offset / 4;
316   psx_sio *sio = &port[ n_port ];
317293   UINT32 data;
318294
319295   switch( offset % 4 )
320296   {
321297   case 0:
322      data = sio->n_rx_data;
323      sio->n_status &= ~( SIO_STATUS_RX_RDY );
324      sio->n_rx_data = 0xff;
325      verboselog( machine(), 1, "psx_sio_r %d data %02x (%08x)\n", n_port, data, mem_mask );
298      data = m_rx_data;
299      m_status &= ~( SIO_STATUS_RX_RDY );
300      m_rx_data = 0xff;
301      verboselog( machine(), 1, "psx_sio_r %s data %02x (%08x)\n", tag(), data, mem_mask );
326302      break;
327303   case 1:
328      data = sio->n_status;
304      data = m_status;
329305      if( ACCESSING_BITS_0_15 )
330306      {
331         verboselog( machine(), 1, "psx_sio_r %d status %04x\n", n_port, data & 0xffff );
307         verboselog( machine(), 1, "psx_sio_r %s status %04x\n", tag(), data & 0xffff );
332308      }
333309      if( ACCESSING_BITS_16_31 )
334310      {
r18804r18805
336312      }
337313      break;
338314   case 2:
339      data = ( sio->n_control << 16 ) | sio->n_mode;
315      data = ( m_control << 16 ) | m_mode;
340316      if( ACCESSING_BITS_0_15 )
341317      {
342         verboselog( machine(), 1, "psx_sio_r %d mode %04x\n", n_port, data & 0xffff );
318         verboselog( machine(), 1, "psx_sio_r %s mode %04x\n", tag(), data & 0xffff );
343319      }
344320      if( ACCESSING_BITS_16_31 )
345321      {
346         verboselog( machine(), 1, "psx_sio_r %d control %04x\n", n_port, data >> 16 );
322         verboselog( machine(), 1, "psx_sio_r %s control %04x\n", tag(), data >> 16 );
347323      }
348324      break;
349325   case 3:
350      data = sio->n_baud << 16;
326      data = m_baud << 16;
351327      if( ACCESSING_BITS_0_15 )
352328      {
353329         verboselog( machine(), 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data );
354330      }
355331      if( ACCESSING_BITS_16_31 )
356332      {
357         verboselog( machine(), 1, "psx_sio_r %d baud %04x\n", n_port, data >> 16 );
333         verboselog( machine(), 1, "psx_sio_r %s baud %04x\n", tag(), data >> 16 );
358334      }
359335      break;
360336   default:
r18804r18805
365341   return data;
366342}
367343
368void psxsio_device::input( int n_port, int n_mask, int n_data )
344void psxsio_device::input( int n_mask, int n_data )
369345{
370   psx_sio *sio = &port[ n_port ];
371   verboselog( machine(), 1, "psx_sio_input( %d, %02x, %02x )\n", n_port, n_mask, n_data );
372   sio->n_rx = ( sio->n_rx & ~n_mask ) | ( n_data & n_mask );
346   verboselog( machine(), 1, "psx_sio_input( %s, %02x, %02x )\n", tag(), n_mask, n_data );
347   m_rx = ( m_rx & ~n_mask ) | ( n_data & n_mask );
373348
374   if( ( sio->n_rx & PSX_SIO_IN_DSR ) != 0 )
349   if( ( m_rx & PSX_SIO_IN_DSR ) != 0 )
375350   {
376      sio->n_status |= SIO_STATUS_DSR;
377      if( ( sio->n_rx_prev & PSX_SIO_IN_DSR ) == 0 &&
378         ( sio->n_control & SIO_CONTROL_DSR_IENA ) != 0 )
351      m_status |= SIO_STATUS_DSR;
352      if( ( m_rx_prev & PSX_SIO_IN_DSR ) == 0 &&
353         ( m_control & SIO_CONTROL_DSR_IENA ) != 0 )
379354      {
380         sio_interrupt( n_port );
355         sio_interrupt();
381356      }
382357   }
383358   else
384359   {
385      sio->n_status &= ~SIO_STATUS_DSR;
360      m_status &= ~SIO_STATUS_DSR;
386361   }
387   sio->n_rx_prev = sio->n_rx;
362   m_rx_prev = m_rx;
388363}
trunk/src/emu/cpu/psx/sio.h
r18804r18805
1212
1313#include "emu.h"
1414
15extern const device_type PSX_SIO;
15extern const device_type PSX_SIO0;
16extern const device_type PSX_SIO1;
1617
1718typedef void ( *psx_sio_handler )( running_machine &, int );
1819
19#define MCFG_PSX_SIO_IRQ0_HANDLER(_devcb) \
20   devcb = &psxsio_device::set_irq0_handler(*device, DEVCB2_##_devcb); \
20#define MCFG_PSX_SIO_IRQ_HANDLER(_devcb) \
21   devcb = &psxsio_device::set_irq_handler(*device, DEVCB2_##_devcb); \
2122
22#define MCFG_PSX_SIO_IRQ1_HANDLER(_devcb) \
23   devcb = &psxsio_device::set_irq1_handler(*device, DEVCB2_##_devcb); \
24
2523#define PSX_SIO_OUT_DATA ( 1 )   /* COMMAND */
2624#define PSX_SIO_OUT_DTR ( 2 )   /* ATT */
2725#define PSX_SIO_OUT_RTS ( 4 )
r18804r18805
4745#define SIO_CONTROL_DSR_IENA ( 1 << 12 )
4846#define SIO_CONTROL_DTR ( 1 << 13 )
4947
50struct psx_sio
51{
52   UINT32 n_status;
53   UINT32 n_mode;
54   UINT32 n_control;
55   UINT32 n_baud;
56   UINT32 n_tx;
57   UINT32 n_rx;
58   UINT32 n_tx_prev;
59   UINT32 n_rx_prev;
60   UINT32 n_tx_data;
61   UINT32 n_rx_data;
62   UINT32 n_tx_shift;
63   UINT32 n_rx_shift;
64   UINT32 n_tx_bits;
65   UINT32 n_rx_bits;
66
67   emu_timer *timer;
68   psx_sio_handler fn_handler;
69};
70
7148class psxsio_device : public device_t
7249{
7350public:
74   psxsio_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
51   psxsio_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock);
7552
7653   // static configuration helpers
77   template<class _Object> static devcb2_base &set_irq0_handler(device_t &device, _Object object) { return downcast<psxsio_device &>(device).m_irq0_handler.set_callback(object); }
78   template<class _Object> static devcb2_base &set_irq1_handler(device_t &device, _Object object) { return downcast<psxsio_device &>(device).m_irq1_handler.set_callback(object); }
54   template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<psxsio_device &>(device).m_irq_handler.set_callback(object); }
7955
80   void install_handler( int n_port, psx_sio_handler p_f_sio_handler );
56   void install_handler( psx_sio_handler p_f_sio_handler );
8157
8258   DECLARE_WRITE32_MEMBER( write );
8359   DECLARE_READ32_MEMBER( read );
8460
85   void input( int n_port, int n_mask, int n_data );
61   void input( int n_mask, int n_data );
8662
8763protected:
64   // device-level overrides
8865   virtual void device_start();
89   virtual void device_reset();
66   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
9067   virtual void device_post_load();
9168
9269private:
93   void sio_interrupt( int n_port );
94   void sio_timer_adjust( int n_port );
95   TIMER_CALLBACK_MEMBER(sio_clock);
70   void sio_interrupt();
71   void sio_timer_adjust();
9672
97   psx_sio port[2];
73   UINT32 m_status;
74   UINT32 m_mode;
75   UINT32 m_control;
76   UINT32 m_baud;
77   UINT32 m_tx;
78   UINT32 m_rx;
79   UINT32 m_tx_prev;
80   UINT32 m_rx_prev;
81   UINT32 m_tx_data;
82   UINT32 m_rx_data;
83   UINT32 m_tx_shift;
84   UINT32 m_rx_shift;
85   UINT32 m_tx_bits;
86   UINT32 m_rx_bits;
9887
99   devcb2_write_line m_irq0_handler;
100   devcb2_write_line m_irq1_handler;
88   emu_timer *m_timer;
89   psx_sio_handler m_fn_handler;
90
91   devcb2_write_line m_irq_handler;
10192};
10293
94class psxsio0_device : public psxsio_device
95{
96public:
97   psxsio0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
98};
99
100class psxsio1_device : public psxsio_device
101{
102public:
103   psxsio1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
104};
105
103106#endif

Previous 199869 Revisions Next


© 1997-2024 The MAME Team