Previous 15994 Revisions Next

r9744 Tuesday 7th December, 2010 at 02:47:27 UTC by R. Belmont
A bunch of device fixes and enhancements [Hans Ostermeyer]
[src/emu/machine]6840ptm.c 68681.c 8237dma.c mc146818.c mc146818.h pic8259.c

src/emu/machine/mc146818.h
r9743r9744
4848   {
4949      MC146818_STANDARD,
5050      MC146818_IGNORE_CENTURY, // century is NOT set, for systems having other usage of this byte
51      MC146818_ENHANCED
51      MC146818_ENHANCED,
52      MC146818_UTC
5253   };
5354
5455   // allocators
src/emu/machine/68681.c
r9743r9744
88#include "emu.h"
99#include "68681.h"
1010
11#define VERBOSE 1
11#define VERBOSE
1212#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
1313
1414static const char *const duart68681_reg_read_names[0x10] =
r9743r9744
242242
243243   duart68681->ISR |= INT_COUNTER_READY;
244244   duart68681_update_interrupts(duart68681);
245
246//   if ((duart68681->OPCR & 0x0c)== 0x04) {
247//      duart68681->OPR ^= 0x08;
248//      if (duart68681->duart_config->output_port_write)
249//         duart68681->duart_config->output_port_write(duart68681->device, duart68681->OPR ^ 0xff);
250//
251//   }
245252};
246253
247254static void duart68681_write_MR(duart68681_state *duart68681, int ch, UINT8 data)
r9743r9744
305312static void duart68681_write_CR(duart68681_state *duart68681, int ch, UINT8 data)
306313{
307314   duart68681->channel[ch].CR = data;
308   if ( BIT(data,0) )
309   {
310      duart68681->channel[ch].rx_enabled = 1;
311   }
312   if ( BIT(data,1) )
313   {
314      duart68681->channel[ch].rx_enabled = 0;
315      duart68681->channel[ch].SR &= ~STATUS_RECEIVER_READY; // datasheet explicitly says disabling rx does not affect the reciever ready line, which just indicates if the fifo has anything in it at all.
316   }
317315
318   if ( BIT(data,2) )
319   {
320      duart68681->channel[ch].tx_enabled = 1;
321      duart68681->channel[ch].tx_ready = 1;
322      duart68681->channel[ch].SR |= STATUS_TRANSMITTER_READY;
323      duart68681->channel[ch].SR |= STATUS_TRANSMITTER_EMPTY;
324   }
325   if ( BIT(data,3) )
326   {
327      duart68681->channel[ch].tx_enabled = 0;
328      duart68681->channel[ch].tx_ready = 0;
329      duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_READY;
330      duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_EMPTY;
331   }
332
333316   switch( (data >> 4) & 0x07 )
334317   {
335318      case 0: /* No command */
r9743r9744
348331      case 3: /* Reset channel A transmitter */
349332         duart68681->channel[ch].tx_enabled = 0;
350333         duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_READY;
334         if (ch == 0)
335            duart68681->ISR &= ~INT_TXRDYA;
336         else
337            duart68681->ISR &= ~INT_TXRDYB;
351338         timer_adjust_oneshot(duart68681->channel[ch].tx_timer, attotime_never, ch);
352339         break;
353340      case 4: /* Reset Error Status */
r9743r9744
369356         break;
370357   }
371358   duart68681_update_interrupts(duart68681);
359
360   if (BIT(data, 0)) {
361      duart68681->channel[ch].rx_enabled = 1;
362   }
363   if (BIT(data, 1)) {
364      duart68681->channel[ch].rx_enabled = 0;
365      duart68681->channel[ch].SR &= ~STATUS_RECEIVER_READY;
366   }
367
368   if (BIT(data, 2)) {
369      duart68681->channel[ch].tx_enabled = 1;
370      duart68681->channel[ch].tx_ready = 1;
371      duart68681->channel[ch].SR |= STATUS_TRANSMITTER_READY;
372      if (ch == 0)
373         duart68681->ISR |= INT_TXRDYA;
374      else
375         duart68681->ISR |= INT_TXRDYB;
376   }
377   if (BIT(data, 3)) {
378      duart68681->channel[ch].tx_enabled = 0;
379      duart68681->channel[ch].tx_ready = 0;
380      duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_READY;
381      if (ch == 0)
382         duart68681->ISR &= ~INT_TXRDYA;
383      else
384         duart68681->ISR &= ~INT_TXRDYB;
385   }
386
372387};
373388
374389static UINT8 duart68681_read_rx_fifo(duart68681_state *duart68681, int ch)
r9743r9744
422437
423438   duart68681->channel[ch].tx_data = data;
424439
425   duart68681->channel[ch].tx_ready = 0;
426   duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_READY;
440   // tx_ready will stay on in local loopback mode
441   if ((duart68681->channel[ch].MR2 & 0xc0) != 0x80) {
442      duart68681->channel[ch].tx_ready = 0;
443      duart68681->channel[ch].SR &= ~STATUS_TRANSMITTER_READY;
444   }
427445
428446   if (ch == 0)
429447      duart68681->ISR &= ~INT_TXRDYA;
src/emu/machine/6840ptm.c
r9743r9744
103103    : device_t(_machine, config),
104104      m_config(config)
105105{
106
107106}
108107
109108
r9743r9744
114113void ptm6840_device::device_start()
115114{
116115   m_internal_clock = m_config.m_internal_clock;
117
118116   /* resolve callbacks */
119117   for (int i = 0; i < 3; i++)
120118   {
r9743r9744
181179   m_t3_divisor          = 1;
182180   m_status_read_since_int = 0;
183181   m_IRQ                   = 0;
184
185182   for (int i = 0; i < 3; i++)
186183   {
187184      m_counter[i] = 0xffff;
r9743r9744
676673
677674            /* No changes in output until reinit */
678675            m_fired[idx] = 1;
676
677            m_status_reg |= (1 << idx);
678            m_status_read_since_int &= ~(1 << idx);
679            update_interrupts();
679680         }
680681      }
681682   }
src/emu/machine/pic8259.c
r9743r9744
1818
1919#define LOG_ICW      0
2020#define LOG_OCW      0
21#define LOG_GENERAL   
21#define LOG_GENERAL   
2222
2323typedef enum
2424{
r9743r9744
174174            logerror("pic8259_acknowledge(): PIC acknowledge IRQ #%d\n", irq);
175175         pic8259->irr &= ~mask;
176176         pic8259->esr &= ~mask;
177         pic8259->irq_lines &= ~mask;
178
177179         if (!pic8259->auto_eoi)
178180            pic8259->isr |= mask;
179181         pic8259_set_timer(pic8259);
r9743r9744
205207         {
206208            /* Polling mode */
207209            if ( pic8259->isr & ~pic8259->imr )
210               pic8259_acknowledge( device );
211
212            if ( pic8259->irr & ~pic8259->imr )
208213            {
209214               int irq;
210
211               pic8259_acknowledge( device );
212
213215               for ( irq = 0; irq < IRQ_COUNT; irq++ )
214216               {
215                  if ( ( 1 << irq ) & pic8259->isr & ~pic8259->imr )
217                  if ( ( 1 << irq ) & pic8259->irr & ~pic8259->imr )
216218                  {
217219                     data = 0x80 | irq;
218220                     break;
r9743r9744
269271            pic8259->icw4_needed      = (data & 0x01) ? 1 : 0;
270272            pic8259->vector_addr_low   = (data & 0xe0);
271273            pic8259->state         = STATE_ICW2;
274            pic8259->irq_lines          = 0x00;
272275         }
273276         else if (pic8259->state == STATE_READY)
274277         {
src/emu/machine/8237dma.c
r9743r9744
103103    : device_t(_machine, config),
104104      m_config(config)
105105{
106
107106}
108107
109108//-------------------------------------------------
r9743r9744
141140   m_last_service_channel = 3;
142141
143142   m_command = 0;
143   m_drq = 0;
144144   m_mask = 0x00;
145145   m_status = 0x0F;
146146   m_hrq = 0;
r9743r9744
312312
313313         timer_enable( m_timer, 1 );
314314      }
315      else if (m_command == 3 && (m_drq & 1))
316      {
317         /* Memory-to-memory transfers */
318         m_hlda = 1;
319         m_state = DMA8237_S0;
320      }
315321      else
316322      {
317323         timer_enable( m_timer, 0 );
r9743r9744
440446      i8327_set_dack(-1);
441447      break;
442448
443   case DMA8237_S11:   /* Output A8-A15 */
449   case DMA8237_S11: /* Output A8-A15 */
450
451//      logerror("###### dma8237_timerproc %s: from %04x count=%x to %04x count=%x\n", tag(),
452//            m_chan[0].m_address, m_chan[0].m_count,
453//            m_chan[1].m_address, m_chan[1].m_count);
454
455      // FIXME: this will copy bytes correct, but not 16 bit words
456      m_temporary_data = devcb_call_read8(&m_in_memr_func, m_chan[0].m_address);
457      devcb_call_write8(&m_out_memw_func, m_chan[1].m_address, m_temporary_data);
458
459      m_service_channel = 0;
460
461      /* Advance */
462      i8237_advance();
463
464      // advance destination channel as well
465      m_chan[1].m_count--;
466      m_chan[1].m_address++;
467
468      if (m_chan[0].m_count == 0xFFFF || m_chan[1].m_count == 0xFFFF) {
469         m_hrq = 0;
470         m_hlda = 0;
471         devcb_call_write_line(&m_out_hrq_func, m_hrq);
472         m_state = DMA8237_SI;
473         m_status |= 3; // set TC for channel 0 and 1
474         m_drq &= ~3; // clear drq for channel 0 and 1
475
476      //   logerror("!!! dma8237_timerproc DMA8237_S11 %s: m_drq=%x m_command=%x\n", tag(), m_drq, m_command);
477      }
444478      break;
445479   }
446480}
r9743r9744
506540{
507541   offset &= 0x0F;
508542
509   logerror("i8237_w: offset = %02x, data = %02x\n", offset, data );
543//   logerror("i8237_w: offset = %02x, data = %02x\n", offset, data );
510544
511545   switch(offset) {
512546   case 0:
r9743r9744
611645      m_mask = 0x0f;
612646      m_state = DMA8237_SI;
613647      m_status &= 0xF0;
648      m_temp = 0;
614649      break;
615650
616651   case 14:
r9743r9744
639674   }
640675
641676   timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 );
677
642678}
643679
644680
src/emu/machine/mc146818.c
r9743r9744
8888//  MACROS
8989//**************************************************************************
9090
91#define USE_UTC      1
92
9193#define HOURS_24   (m_data[0xb]&2)
9294#define BCD_MODE   !(m_data[0xb]&4) // book has other description!
93#define CENTURY      m_data[50]
95#define CENTURY      m_data[100]
9496#define YEAR      m_data[9]
9597#define MONTH      m_data[8]
9698#define DAY         m_data[7]
r9743r9744
183185{
184186   m_last_refresh = timer_get_time(&m_machine);
185187   emu_timer *timer = device_timer_alloc(*this);
186   timer_adjust_periodic(timer, ATTOTIME_IN_HZ(1), 0, ATTOTIME_IN_HZ(1));
188   if (m_config.m_type == mc146818_device_config::MC146818_UTC) {
189      // hack: for apollo we increase the update frequency to stay in sync with real time
190      timer_adjust_periodic(timer, ATTOTIME_IN_HZ(2), 0, ATTOTIME_IN_HZ(2));
191   } else {
192      timer_adjust_periodic(timer, ATTOTIME_IN_HZ(1), 0, ATTOTIME_IN_HZ(1));
193   }
187194   set_base_datetime();
188195}
189196
r9743r9744
196203{
197204   int year/*, month*/;
198205
206   if (m_config.m_type == mc146818_device_config::MC146818_UTC) {
207      // hack: set correct real time even for overloaded emulation
208      // (at least for apollo)
209      static osd_ticks_t t0 = 0;
210      osd_ticks_t t1 = osd_ticks();
211      int n_seconds;
212
213      if (t0 == 0) {
214         t0 = t1;
215      }
216
217      n_seconds =  (t1 - t0) / osd_ticks_per_second();
218      t0 = t1 - (t1 - t0) % osd_ticks_per_second();
219      if (n_seconds <= 0) {
220         // we were called to early
221         return;
222      }
223
224      m_data[0] += n_seconds;
225   } else {
226      m_data[0] += 1;
227   }
228
199229   if (BCD_MODE)
200230   {
201      m_data[0]=bcd_adjust(m_data[0]+1);
231      m_data[0]=bcd_adjust(m_data[0]/*+1*/);
202232      if (m_data[0]>=0x60)
203233      {
204234         m_data[0]=0;
r9743r9744
241271   }
242272   else
243273   {
244      m_data[0]=m_data[0]+1;
274      /*m_data[0]=m_data[0]+1;*/
245275      if (m_data[0]>=60)
246276      {
247         m_data[0]=0;
277         m_data[0] -= 60;
248278         m_data[2]=m_data[2]+1;
249279         if (m_data[2]>=60) {
250280            m_data[2]=0;
r9743r9744
272302         }
273303      }
274304   }
305
306   if (m_data[1] == m_data[0] && //
307      m_data[3] == m_data[2] && //
308      m_data[5] == m_data[4]) {
309      // set the alarm interrupt flag AF
310      m_data[0x0c] |= 0x20;
311   } else {
312      // clear the alarm interrupt flag AF
313      m_data[0x0c] &= ~0x20;
314      if ((m_data[0x0c] & 0x70) == 0) {
315         // clear IRQF
316         m_data[0x0c] &= ~0x80;
317      }
318   }
319
320   // set the update-ended interrupt Flag UF
321   m_data[0x0c] |=  0x10;
322
323   // set the interrupt request flag IRQF
324   // FIXME: should throw IRQ line as well
325   if ((m_data[0x0b] & m_data[0x0c] & 0x70) != 0) {
326      m_data[0x0c] |=  0x80;
327   }
328
275329   m_updated = true;  /* clock has been updated */
276330   m_last_refresh = timer_get_time(&m_machine);
277331}
r9743r9744
297351void mc146818_device::nvram_read(mame_file &file)
298352{
299353   mame_fread(&file, m_data, sizeof(m_data));
354   set_base_datetime();
300355}
301356
302357
r9743r9744
330385void mc146818_device::set_base_datetime()
331386{
332387   system_time systime;
388   system_time::full_time current_time;
333389
334390   m_machine.base_datetime(systime);
335391
336   if (HOURS_24 || (systime.local_time.hour < 12))
337      m_data[4] = dec_2_local(systime.local_time.hour);
392   current_time = m_config.m_type == mc146818_device_config::MC146818_UTC ? systime.utc_time: systime.local_time;
393
394   // temporary hack to go back 20 year (e.g. from 2010 -> 1990)
395   // current_time.year -= 20;
396
397//   logerror("mc146818_set_base_datetime %02d/%02d/%02d %02d:%02d:%02d\n",
398//         current_time.year % 100, current_time.month + 1, current_time.mday,
399//         current_time.hour,current_time.minute, current_time.second);
400
401   if (HOURS_24 || (current_time.hour < 12))
402      m_data[4] = dec_2_local(current_time.hour);
338403   else
339      m_data[4] = dec_2_local(systime.local_time.hour - 12) | 0x80;
404      m_data[4] = dec_2_local(current_time.hour - 12) | 0x80;
340405
341406   if (m_config.m_type != mc146818_device_config::MC146818_IGNORE_CENTURY)
342      CENTURY = dec_2_local(systime.local_time.year /100);
407      CENTURY = dec_2_local(current_time.year /100);
343408
344   m_data[0]   = dec_2_local(systime.local_time.second);
345   m_data[2]   = dec_2_local(systime.local_time.minute);
346   DAY               = dec_2_local(systime.local_time.day);
347   MONTH            = dec_2_local(systime.local_time.month + 1);
348   YEAR            = dec_2_local(systime.local_time.year % 100);
409   m_data[0]   = dec_2_local(current_time.second);
410   m_data[2]   = dec_2_local(current_time.minute);
411   DAY               = dec_2_local(current_time.mday);
412   MONTH            = dec_2_local(current_time.month + 1);
413   YEAR            = dec_2_local(current_time.year % 100);
349414
350   WEEK_DAY = systime.local_time.weekday;
351   if (systime.local_time.is_dst)
415   WEEK_DAY = current_time.weekday;
416   if (current_time.is_dst)
352417      m_data[0xb] |= 1;
353418   else
354419      m_data[0xb] &= ~1;
r9743r9744
380445         break;
381446
382447      case 0xc:
383         if (m_updated) /* the clock has been updated */
384            data = 0x10;
385         else
386            data = 0x00;
448//          if(m_updated) /* the clock has been updated */
449//            data = 0x10;
450//          else
451//             data = 0x00;
452         // the unused bits b0 ... b3 are always read as 0
453         data = m_data[m_index % MC146818_DATA_SIZE] & 0xf0;
454         // read 0x0c will clear all IRQ flags in register 0x0c
455         m_data[m_index % MC146818_DATA_SIZE] &= 0x0f;
387456         break;
388457      case 0xd:
389458         /* battery ok */
r9743r9744
425494            m_updated = false;
426495         m_data[m_index % MC146818_DATA_SIZE] = data;
427496         break;
497      case 0x0c:
498         // register 0x0c is readonly
499         break;
428500      default:
429501         m_data[m_index % MC146818_DATA_SIZE] = data;
430502      }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team