Previous 15994 Revisions Next

r1138 Thursday 18th October, 2007 at 09:02:45 UTC by Curt Coder
[ATARIST] Added serial I/O to M6800 cpu core and rewrote ACIA6850. As a result, the IKBD<->CPU communication now works in Atari ST!
[src/emu/cpu/m6800]m6800.c
[src/emu/machine]6850acia.c 6850acia.h
[src/mess/drivers]atarist.c

src/emu/cpu/m6800/m6800.c
r1137r1138
112112   PAIR   output_compare;   /* output compare       */
113113   UINT16   input_capture;   /* input capture        */
114114
115   int      clock;
116   UINT8   trcsr, rmcr, rdr, tdr, rsr, tsr;
117   int      rxbits, txbits, txstate, trcsr_read, tx;
118
115119   PAIR   timer_over;
116120}   m6800_Regs;
117121
118122/* 680x registers */
119123static m6800_Regs m6800;
120124
125static mame_timer *m6800_rx_timer;
126static mame_timer *m6800_tx_timer;
127
121128#define m6801   m6800
122129#define m6802   m6800
123130#define m6803   m6800
r1137r1138
197204   SET_TIMER_EVENT;                     \
198205}
199206
207// serial I/O
208
209#define M6800_RMCR_SS_MASK      0x03 // Speed Select
210#define M6800_RMCR_SS_4096      0x03 // E / 4096
211#define M6800_RMCR_SS_1024      0x02 // E / 1024
212#define M6800_RMCR_SS_128      0x01 // E / 128
213#define M6800_RMCR_SS_16      0x00 // E / 16
214#define M6800_RMCR_CC_MASK      0x0c // Clock Control/Format Select
215
216#define M6800_TRCSR_RDRF      0x80 // Receive Data Register Full
217#define M6800_TRCSR_ORFE      0x40 // Over Run Framing Error
218#define M6800_TRCSR_TDRE      0x20 // Transmit Data Register Empty
219#define M6800_TRCSR_RIE      0x10 // Receive Interrupt Enable
220#define M6800_TRCSR_RE         0x08 // Receive Enable
221#define M6800_TRCSR_TIE      0x04 // Transmit Interrupt Enable
222#define M6800_TRCSR_TE         0x02 // Transmit Enable
223#define M6800_TRCSR_WU         0x01 // Wake Up
224
225#define M6800_PORT2_IO4      0x10
226#define M6800_PORT2_IO3      0x08
227
228static const int M6800_RMCR_SS[] = { 16, 128, 1024, 4096 };
229
230#define M6800_SERIAL_START      0
231#define M6800_SERIAL_STOP      9
232
233enum
234{
235   M6800_TX_STATE_INIT = 0,
236   M6800_TX_STATE_READY
237};
238
200239/* take interrupt */
201240#define TAKE_ICI ENTER_INTERRUPT("M6800#%d take ICI\n",0xfff6)
202241#define TAKE_OCI ENTER_INTERRUPT("M6800#%d take OCI\n",0xfff4)
r1137r1138
204243#define TAKE_SCI ENTER_INTERRUPT("M6800#%d take SCI\n",0xfff0)
205244#define TAKE_TRAP ENTER_INTERRUPT("M6800#%d take TRAP\n",0xffee)
206245
207/* check IRQ2 (internal irq) */
208#define CHECK_IRQ2 {                                 \
209   if(m6800.irq2&(TCSR_ICF|TCSR_OCF|TCSR_TOF))               \
210   {                                             \
211      if(m6800.irq2&TCSR_ICF)                           \
212      {                                          \
213         TAKE_ICI;                                 \
214         if( m6800.irq_callback )                     \
215            (void)(*m6800.irq_callback)(M6800_TIN_LINE);   \
216      }                                          \
217      else if(m6800.irq2&TCSR_OCF)                     \
218      {                                          \
219         TAKE_OCI;                                 \
220      }                                          \
221      else if(m6800.irq2&TCSR_TOF)                     \
222      {                                          \
223         TAKE_TOI;                                 \
224      }                                          \
225   }                                             \
226}
227
228246/* operate one instruction for */
229247#define ONE_MORE_INSN() {      \
230248   UINT8 ireg;                      \
r1137r1138
247265            (void)(*m6800.irq_callback)(M6800_IRQ_LINE);   \
248266      }                                          \
249267      else                                       \
250         CHECK_IRQ2;                                 \
268         m6800_check_irq2();                           \
251269   }                                             \
252270}
253271
r1137r1138
511529   CHANGE_PC();
512530}
513531
532void m6800_check_irq2(void)
533{
534   if ((m6800.tcsr & (TCSR_EICI|TCSR_ICF)) == (TCSR_EICI|TCSR_ICF))
535   {
536      TAKE_ICI;
537      if( m6800.irq_callback )
538         (void)(*m6800.irq_callback)(M6800_TIN_LINE);
539   }
540   else if ((m6800.tcsr & (TCSR_EOCI|TCSR_OCF)) == (TCSR_EOCI|TCSR_OCF))
541   {
542      TAKE_OCI;
543   }
544   else if ((m6800.tcsr & (TCSR_ETOI|TCSR_TOF)) == (TCSR_ETOI|TCSR_TOF))
545   {
546      TAKE_TOI;
547   }
548   else if (((m6800.trcsr & (M6800_TRCSR_RIE|M6800_TRCSR_RDRF)) == (M6800_TRCSR_RIE|M6800_TRCSR_RDRF)) ||
549          ((m6800.trcsr & (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) == (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) ||
550          ((m6800.trcsr & (M6800_TRCSR_TIE|M6800_TRCSR_TDRE)) == (M6800_TRCSR_TIE|M6800_TRCSR_TDRE)))
551   {
552      TAKE_SCI;
553   }
554}
555
514556/* check OCI or TOI */
515557static void check_timer_event(void)
516558{
r1137r1138
547589/* include the opcode functions */
548590#include "6800ops.c"
549591
592static void m6800_tx(int value)
593{
594   m6800.port2_data = (m6800.port2_data & 0xef) | (value << 4);
595
596   if(m6800.port2_ddr == 0xff)
597      io_write_byte_8(M6803_PORT2,m6800.port2_data);
598   else
599      io_write_byte_8(M6803_PORT2,(m6800.port2_data & m6800.port2_ddr)
600         | (io_read_byte_8(M6803_PORT2) & (m6800.port2_ddr ^ 0xff)));
601}
602
603static int m6800_rx(void)
604{
605   return (io_read_byte_8(M6803_PORT2) & M6800_PORT2_IO3) >> 3;
606}
607
608static TIMER_CALLBACK(m6800_tx_tick)
609{
610    int cpunum = param;
611
612   if (m6800.trcsr & M6800_TRCSR_TE)
613   {
614      // force Port 2 bit 4 as output
615      m6800.port2_ddr |= M6800_PORT2_IO4;
616
617      switch (m6800.txstate)
618      {
619      case M6800_TX_STATE_INIT:
620         m6800.tx = 1;
621         m6800.txbits++;
622
623         if (m6800.txbits == 10)
624         {
625            m6800.txstate = M6800_TX_STATE_READY;
626            m6800.txbits = M6800_SERIAL_START;
627         }
628         break;
629
630      case M6800_TX_STATE_READY:
631         switch (m6800.txbits)
632         {
633         case M6800_SERIAL_START:
634            if (m6800.trcsr & M6800_TRCSR_TDRE)
635            {
636               // transmit buffer is empty, send consecutive '1's
637               m6800.tx = 1;
638            }
639            else
640            {
641               // transmit buffer is full, send data
642
643               // load TDR to shift register
644               m6800.tsr = m6800.tdr;
645
646               // transmit buffer is empty, set TDRE flag
647               m6800.trcsr |= M6800_TRCSR_TDRE;
648
649               // send start bit '0'
650               m6800.tx = 0;
651
652               m6800.txbits++;
653            }
654            break;
655
656         case M6800_SERIAL_STOP:
657            // send stop bit '1'
658            m6800.tx = 1;
659
660             cpuintrf_push_context(cpunum);
661            CHECK_IRQ_LINES();
662            cpuintrf_pop_context();
663
664            m6800.txbits = M6800_SERIAL_START;
665            break;
666
667         default:
668            // send data bit '0' or '1'
669            m6800.tx = m6800.tsr & 0x01;
670
671            // shift transmit register
672            m6800.tsr >>= 1;
673
674            m6800.txbits++;
675            break;
676         }
677         break;
678      }
679   }
680
681   m6800_tx(m6800.tx);
682}
683
684static TIMER_CALLBACK(m6800_rx_tick)
685{
686    int cpunum = param;
687
688   if (m6800.trcsr & M6800_TRCSR_RE)
689   {
690      if (m6800.trcsr & M6800_TRCSR_WU)
691      {
692         // wait for 10 bits of '1'
693
694         if (m6800_rx() == 1)
695         {
696            m6800.rxbits++;
697
698            if (m6800.rxbits == 10)
699            {
700               m6800.trcsr &= ~M6800_TRCSR_WU;
701               m6800.rxbits = M6800_SERIAL_START;
702            }
703         }
704         else
705         {
706            m6800.rxbits = M6800_SERIAL_START;
707         }
708      }
709      else
710      {
711         // receive data
712
713         switch (m6800.rxbits)
714         {
715         case M6800_SERIAL_START:
716            if (m6800_rx() == 0)
717            {
718               // start bit found
719               m6800.rxbits++;
720            }
721            break;
722
723         case M6800_SERIAL_STOP:
724            if (m6800_rx() == 1)
725            {
726               if (m6800.trcsr & M6800_TRCSR_RDRF)
727               {
728                  // overrun error
729
730                  m6800.trcsr |= M6800_TRCSR_ORFE;
731
732                   cpuintrf_push_context(cpunum);
733                  CHECK_IRQ_LINES();
734                  cpuintrf_pop_context();
735               }
736               else
737               {
738                  if (!(m6800.trcsr & M6800_TRCSR_ORFE))
739                  {
740                     // transfer data into receive register
741                     m6800.rdr = m6800.rsr;
742
743                     // set RDRF flag
744                     m6800.trcsr |= M6800_TRCSR_RDRF;
745
746                     cpuintrf_push_context(cpunum);
747                     CHECK_IRQ_LINES();
748                     cpuintrf_pop_context();
749                  }
750               }
751            }
752            else
753            {
754               // framing error
755
756               if (!(m6800.trcsr & M6800_TRCSR_ORFE))
757               {
758                  // transfer unframed data into receive register
759                  m6800.rdr = m6800.rsr;
760               }
761
762               m6800.trcsr |= M6800_TRCSR_ORFE;
763               m6800.trcsr &= ~M6800_TRCSR_RDRF;
764
765               cpuintrf_push_context(cpunum);
766               CHECK_IRQ_LINES();
767               cpuintrf_pop_context();
768            }
769
770            m6800.rxbits = M6800_SERIAL_START;
771            break;
772
773         default:
774            // shift receive register
775            m6800.rsr >>= 1;
776
777            // receive bit into register
778            m6800.rsr |= (m6800_rx() << 7);
779
780            m6800.rxbits++;
781            break;
782         }
783      }
784   }
785}
786
550787/****************************************************************************
551788 * Reset registers to their initial values
552789 ****************************************************************************/
r1137r1138
609846   OCD = 0xffff;
610847   TOD = 0xffff;
611848   m6800.ram_ctrl |= 0x40;
849
850#if (HAS_HD63701)
851   m6800.trcsr = M6800_TRCSR_TDRE;
852   m6800.rmcr = 0;
853   mame_timer_enable(m6800_rx_timer, 0);
854   mame_timer_enable(m6800_tx_timer, 0);
855   m6800.txstate = M6800_TX_STATE_INIT;
856   m6800.txbits = m6800.rxbits = 0;
857   m6800.trcsr_read = 0;
858#endif
612859}
613860
614861/****************************************************************************
r1137r1138
676923         m6800.input_capture = CT;
677924         MODIFIED_tcsr;
678925         if( !(CC & 0x10) )
679            CHECK_IRQ2
926            m6800_check_irq2();
680927         break;
681928      default:
682929         return;
r1137r1138
13481595 * HD63701 similiar to the M6800
13491596 ****************************************************************************/
13501597#if (HAS_HD63701)
1598
13511599static void hd63701_init(int index, int clock, const void *config, int (*irqcallback)(int))
13521600{
13531601//  m6800.subtype = SUBTYPE_HD63701;
13541602   m6800.insn = hd63701_insn;
13551603   m6800.cycles = cycles_63701;
13561604   m6800.irq_callback = irqcallback;
1605
1606   m6800.clock = clock;
1607   m6800_rx_timer = mame_timer_alloc(m6800_rx_tick);
1608   m6800_tx_timer = mame_timer_alloc(m6800_tx_tick);
1609
13571610   state_register("hd63701", index);
13581611}
13591612/****************************************************************************
r1137r1138
20122265               | (m6800.port4_data & m6800.port4_ddr);
20132266      case 0x08:
20142267         m6800.pending_tcsr = 0;
2015//logerror("CPU #%d PC %04x: warning - read TCSR register\n",cpu_getactivecpu(),activecpu_get_pc());
20162268         return m6800.tcsr;
20172269      case 0x09:
20182270         if(!(m6800.pending_tcsr&TCSR_TOF))
r1137r1138
20472299      case 0x0e:
20482300         return (m6800.input_capture >> 8) & 0xff;
20492301      case 0x0f:
2302         logerror("CPU #%d PC %04x: warning - read from unsupported register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),offset);
2303         return 0;
20502304      case 0x10:
2305         return m6800.rmcr;
20512306      case 0x11:
2307         m6800.trcsr_read = 1;
2308         return m6800.trcsr;
20522309      case 0x12:
2310         if (m6800.trcsr_read)
2311         {
2312            m6800.trcsr_read = 0;
2313            m6800.trcsr = m6800.trcsr & 0x3f;
2314         }
2315         return m6800.rdr;
20532316      case 0x13:
2054         logerror("CPU #%d PC %04x: warning - read from unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),offset);
2055         return 0;
2317         return m6800.tdr;
20562318      case 0x14:
20572319         logerror("CPU #%d PC %04x: read RAM control register\n",cpu_getactivecpu(),activecpu_get_pc());
20582320         return m6800.ram_ctrl;
r1137r1138
21132375               | (io_read_byte_8(M6803_PORT1) & (m6800.port1_ddr ^ 0xff)));
21142376         break;
21152377      case 0x03:
2116         m6800.port2_data = data;
2117         m6800.port2_ddr = data;
2378         m6800.port2_data = (m6800.port2_data & 0xef) | (m6800.tx << 4);
21182379         if(m6800.port2_ddr == 0xff)
21192380            io_write_byte_8(M6803_PORT2,m6800.port2_data);
21202381         else
r1137r1138
21642425         m6800.pending_tcsr &= m6800.tcsr;
21652426         MODIFIED_tcsr;
21662427         if( !(CC & 0x10) )
2167            CHECK_IRQ2;
2168//logerror("CPU #%d PC %04x: TCSR = %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data);
2428            m6800_check_irq2();
21692429         break;
21702430      case 0x09:
21712431         latch09 = data & 0xff;   /* 6301 only */
r1137r1138
21942454         break;
21952455      case 0x0d:
21962456      case 0x0e:
2457      case 0x12:
21972458         logerror("CPU #%d PC %04x: warning - write %02x to read only internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset);
21982459         break;
21992460      case 0x0f:
2461         logerror("CPU #%d PC %04x: warning - write %02x to unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset);
2462         break;
22002463      case 0x10:
2464         m6800.rmcr = data & 0x0f;
2465
2466         switch ((m6800.rmcr & M6800_RMCR_CC_MASK) >> 2)
2467         {
2468         case 0:
2469         case 3: // not implemented
2470            mame_timer_enable(m6800_rx_timer, 0);
2471            mame_timer_enable(m6800_tx_timer, 0);
2472            break;
2473
2474         case 1:
2475         case 2:
2476            {
2477               int divisor = M6800_RMCR_SS[m6800.rmcr & M6800_RMCR_SS_MASK];
2478
2479               mame_timer_adjust(m6800_rx_timer, time_zero, cpu_getactivecpu(), MAME_TIME_IN_HZ(m6800.clock / divisor));
2480               mame_timer_adjust(m6800_tx_timer, time_zero, cpu_getactivecpu(), MAME_TIME_IN_HZ(m6800.clock / divisor));
2481            }
2482            break;
2483         }
2484         break;
22012485      case 0x11:
2202      case 0x12:
2486         if ((data & M6800_TRCSR_TE) && !(m6800.trcsr & M6800_TRCSR_TE))
2487         {
2488            m6800.txstate = M6800_TX_STATE_INIT;
2489         }
2490         m6800.trcsr = (m6800.trcsr & 0xe0) | (data & 0x1f);
2491         break;
22032492      case 0x13:
2204         logerror("CPU #%d PC %04x: warning - write %02x to unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset);
2493         if (m6800.trcsr_read)
2494         {
2495            m6800.trcsr_read = 0;
2496            m6800.trcsr &= ~M6800_TRCSR_TDRE;
2497         }
2498         m6800.tdr = data;
22052499         break;
22062500      case 0x14:
22072501         logerror("CPU #%d PC %04x: write %02x to RAM control register\n",cpu_getactivecpu(),activecpu_get_pc(),data);
r1137r1138
22772571      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
22782572      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
22792573      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
2280      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
2574      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 9;               break;
22812575      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
22822576      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
22832577
src/emu/machine/6850acia.c
r1137r1138
11/*
22    6850 ACIA
3*/
34
4    Preliminary and not yet tested outside of bfcobra.c!
5*/
65#include "driver.h"
76#include "timer.h"
87#include "6850acia.h"
r1137r1138
1211#define CR6_5   0x60
1312#define CR7      0x80
1413
15#define STATUS_RDRF   0x01
16#define STATUS_TDRE   0x02
17#define STATUS_DCD   0x04
18#define STATUS_CTS   0x08
19#define STATUS_FE   0x10
20#define STATUS_OVRN   0x20
21#define STATUS_PE   0x40
22#define STATUS_IRQ   0x80
23
2414enum serial_state
2515{
2616   START,
2717   DATA,
2818   PARITY,
2919   STOP,
30   COMPLETE
20   STOP2,
3121};
3222
3323enum parity_type
r1137r1138
3727   EVEN
3828};
3929
40static const int div_type[3] = { 1, 16, 64 };
30static const int ACIA6850_DIVIDE[3] = { 1, 16, 64 };
4131
42static const int wordtype [8][3] =
32static const int ACIA6850_WORD[8][3] =
4333{
44   {7, EVEN, 2},
45   {7, ODD, 2},
46   {7, EVEN, 1},
47   {7, ODD, 1},
48   {8, NONE, 2},
49   {8, NONE, 1},
50   {8, EVEN, 1},
51   {8, ODD, 1}
34   { 7, EVEN, 2 },
35   { 7, ODD,  2 },
36   { 7, EVEN, 1 },
37   { 7, ODD,  1 },
38   { 8, NONE, 2 },
39   { 8, NONE, 1 },
40   { 8, EVEN, 1 },
41   { 8, ODD,  1 }
5242};
5343
5444typedef struct _acia_6850_
r1137r1138
5848
5949   UINT8   *rx_pin;
6050   UINT8   *tx_pin;
51   UINT8   *cts_pin;
52   UINT8   *rts_pin;
53   UINT8   *dcd_pin;
6154
6255   UINT8   tdr;
6356   UINT8   rdr;
r1137r1138
7972   int   bits;
8073   enum    parity_type parity;
8174   int   stopbits;
75   int tx_int;
8276
8377   /* Signals */
8478   int   overrun;
8579   int   reset;
80   int rts;
81   int brk;
82   int first_reset;
83   int status_read;
8684   enum    serial_state rx_state;
8785   enum    serial_state tx_state;
8886
r1137r1138
10098/*
10199    Reset the chip
102100*/
103static void reset(int which)
101static void acia6850_reset(int which)
104102{
105103   acia_6850 *acia_p = &acia[which];
104   int cts = 0, dcd = 0;
106105
107   acia_p->status = STATUS_TDRE;
106   if (acia_p->cts_pin)
107   {
108      cts = *acia_p->cts_pin;
109   }
110
111   if (acia_p->dcd_pin)
112   {
113      dcd = *acia_p->dcd_pin;
114   }
115
116   acia_p->status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE;
108117   acia_p->tdr = 0;
109118   acia_p->rdr = 0;
110119   acia_p->tx_shift = 0;
111120   acia_p->rx_shift = 0;
112121   *acia_p->tx_pin = 1;
122   acia_p->overrun = 0;
123   acia_p->status_read = 0;
124   acia_p->brk = 0;
113125
126   acia_p->rx_state = START;
114127   acia_p->tx_state = START;
115   acia_p->rx_state = START;
128
129   if (acia_p->int_callback)
130   {
131      acia_p->int_callback(1);
132   }
133
134   if (acia_p->first_reset)
135   {
136      acia_p->first_reset = 0;
137     
138      if (acia_p->rts_pin)
139      {
140         *acia_p->rts_pin = 1;
141      }
142   }
143   else
144   {
145      if (acia_p->rts_pin)
146      {
147         *acia_p->rts_pin = acia_p->rts;
148      }
149   }
116150}
117151
118152/*
r1137r1138
131165   acia_p->tx_clock = intf->tx_clock;
132166   acia_p->rx_pin = intf->rx_pin;
133167   acia_p->tx_pin = intf->tx_pin;
168   acia_p->cts_pin = intf->cts_pin;
169   acia_p->rts_pin = intf->rts_pin;
170   acia_p->dcd_pin = intf->rts_pin;
134171   acia_p->rx_timer = mame_timer_alloc(receive_event);
135172   acia_p->tx_timer = mame_timer_alloc(transmit_event);
136173   acia_p->int_callback = intf->int_callback;
174   acia_p->first_reset = 1;
175   acia_p->status_read = 0;
176   acia_p->brk = 0;
137177
138178   mame_timer_reset(acia_p->rx_timer, time_never);
139179   mame_timer_reset(acia_p->tx_timer, time_never);
140180
141   // TODO
142   *acia_p->tx_pin = 1;
143
144181   state_save_register_item("acia6850", which, acia_p->ctrl);
145182   state_save_register_item("acia6850", which, acia_p->status);
146183   state_save_register_item("acia6850", which, acia_p->rx_clock);
r1137r1138
153190   state_save_register_item("acia6850", which, acia_p->tx_bits);
154191   state_save_register_item("acia6850", which, acia_p->rx_parity);
155192   state_save_register_item("acia6850", which, acia_p->tx_parity);
193   state_save_register_item("acia6850", which, acia_p->tx_int);
156194
157195   state_save_register_item("acia6850", which, acia_p->divide);
158196   state_save_register_item("acia6850", which, acia_p->overrun);
159197   state_save_register_item("acia6850", which, acia_p->reset);
198   state_save_register_item("acia6850", which, acia_p->first_reset);
199   state_save_register_item("acia6850", which, acia_p->rts);
200   state_save_register_item("acia6850", which, acia_p->brk);
201   state_save_register_item("acia6850", which, acia_p->status_read);
160202}
161203
162204/*
r1137r1138
164206*/
165207UINT8 acia6850_stat_r(int which)
166208{
167   return acia[which].status;
209   acia_6850 *acia_p = &acia[which];
210
211   acia_p->status_read = 1;
212   
213   return acia_p->status;
168214}
169215
170216/*
r1137r1138
172218*/
173219void acia6850_ctrl_w(int which, UINT8 data)
174220{
221   acia_6850 *acia_p = &acia[which];
222
175223   int wordsel;
176224   int divide;
177   acia_6850 *acia_p = &acia[which];
178225
179226   acia_p->ctrl = data;
180227
181   /* 1. Counter divide select */
228   // Counter Divide Select Bits
229
182230   divide = data & CR1_0;
183231
184232   if (divide == 3)
185233   {
186234      acia_p->reset = 1;
187      reset(which);
235      acia6850_reset(which);
188236   }
189237   else
190238   {
191239      acia_p->reset = 0;
192      acia_p->divide = div_type[divide];
240      acia_p->divide = ACIA6850_DIVIDE[divide];
193241   }
194242
195   /* 2. Word type */
243   // Word Select Bits
244
196245   wordsel = (data & CR4_2) >> 2;
197   acia_p->bits = wordtype[wordsel][0];
198   acia_p->parity = wordtype[wordsel][1];
199   acia_p->stopbits = wordtype[wordsel][2];
200246
201   /* 3. TX Control (TODO) */
247   acia_p->bits = ACIA6850_WORD[wordsel][0];
248   acia_p->parity = ACIA6850_WORD[wordsel][1];
249   acia_p->stopbits = ACIA6850_WORD[wordsel][2];
202250
203   /* After writing the word type, start receive clock */
204   if(!acia_p->reset)
251   // Transmitter Control Bits
252
253   switch ((data & CR6_5) >> 5)
205254   {
206      mame_time period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->rx_clock), acia_p->divide);
207      /* TODO! */
208      mame_timer_adjust(acia_p->rx_timer, period, which, period);
255   case 0:
256      if (acia_p->rts_pin)
257      {
258         *acia_p->rts_pin = acia_p->rts = 0;
259      }
260
261      acia_p->tx_int = 0;
262      acia_p->brk = 0;
263      break;
264
265   case 1:
266      if (acia_p->rts_pin)
267      {
268         *acia_p->rts_pin = acia_p->rts = 0;
269      }
270
271      acia_p->tx_int = 1;
272      acia_p->brk = 0;
273      break;
274
275   case 2:
276      if (acia_p->rts_pin)
277      {
278         *acia_p->rts_pin = acia_p->rts = 1;
279      }
280
281      acia_p->tx_int = 0;
282      acia_p->brk = 0;
283      break;
284
285   case 3:
286      if (acia_p->rts_pin)
287      {
288         *acia_p->rts_pin = acia_p->rts = 0;
289      }
290
291      acia_p->tx_int = 0;
292      acia_p->brk = 1;
293      break;
209294   }
295
296   // After writing the word type, start receive clock
297
298   if (!acia_p->reset)
299   {
300      mame_time rx_period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->rx_clock), acia_p->divide);
301      mame_time tx_period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->tx_clock), acia_p->divide);
302      mame_timer_adjust(acia_p->rx_timer, rx_period, which, rx_period);
303      mame_timer_adjust(acia_p->tx_timer, tx_period, which, tx_period);
304   }
210305}
211306
212static TIMER_CALLBACK( tdr_to_shift )
307void acia6850_check_interrupts(int which)
213308{
214      int which = param;
309   acia_6850 *acia_p = &acia[which];
215310
216      acia_6850 *acia_p = &acia[which];
217      mame_time period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->tx_clock), acia_p->divide);
311   int irq = (acia_p->tx_int && (acia_p->status & ACIA6850_STATUS_TDRE)) ||
312      ((acia_p->ctrl & 0x80) && ((acia_p->status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || acia_p->overrun));
218313
219      acia_p->tx_shift = acia[which].tdr;
220      acia_p->status &= ~STATUS_TDRE;
314   if (irq)
315   {
316      acia_p->status |= ACIA6850_STATUS_IRQ;
221317
222      /* Start the transmit timer */
223      mame_timer_adjust(acia_p->tx_timer, period, which, period);
318      if (acia_p->int_callback)
319      {
320         acia_p->int_callback(0);
321      }
322   }
323   else
324   {
325      acia_p->status &= ~ACIA6850_STATUS_IRQ;
326
327      if (acia_p->int_callback)
328      {
329         acia_p->int_callback(1);
330      }
331   }
224332}
225333
226
227334/*
228335    Write transmit register
229336*/
230337void acia6850_data_w(int which, UINT8 data)
231338{
232   if (!acia[which].reset)
339   acia_6850 *acia_p = &acia[which];
340
341   if (!acia_p->reset)
233342   {
234      acia[which].tdr = data;
235      timer_call_after_resynch(which, tdr_to_shift);
236      //printf("ACIA %d Transmit: %x (%c)\n", which, data, data);
343      acia_p->tdr = data;
344      acia_p->status &= ~ACIA6850_STATUS_TDRE;
345      acia6850_check_interrupts(which);
237346   }
238347   else
239348   {
r1137r1138
246355*/
247356UINT8 acia6850_data_r(int which)
248357{
249   acia[which].status &= ~(STATUS_RDRF | STATUS_IRQ | STATUS_PE | STATUS_OVRN);
358   acia_6850 *acia_p = &acia[which];
250359
251   if (acia[which].int_callback)
252      acia[which].int_callback(0);
360   acia_p->status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE);
253361
254   return acia[which].rdr;
362   if (acia_p->status_read)
363   {
364      acia_p->status_read = 0;
365      acia_p->status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD);
366
367      if (acia_p->dcd_pin && *acia_p->dcd_pin)
368      {
369         acia_p->status |= ACIA6850_STATUS_DCD;
370      }
371   }
372
373   if (acia_p->overrun == 1)
374   {
375      acia_p->status |= ACIA6850_STATUS_OVRN;
376      acia_p->overrun = 0;
377   }
378
379   acia6850_check_interrupts(which);
380
381   return acia_p->rdr;
255382}
256383
257
258384/*
259385    Transmit a bit
260386*/
r1137r1138
267393   {
268394      case START:
269395      {
270         /* Stop bit */
271         *acia_p->tx_pin = 0;
272         acia_p->tx_bits = acia_p->bits;
273         acia_p->tx_state = DATA;
396         if (acia_p->brk)
397         {
398            // transmit break
399
400            *acia_p->tx_pin = 0;
401         }
402         else
403         {
404            if (acia_p->status & ACIA6850_STATUS_TDRE)
405            {
406               // transmitter idle
407
408               *acia_p->tx_pin = 1;
409            }
410            else
411            {
412               // transmit character
413
414               //logerror("ACIA6850 #%u: TX DATA %x\n", which, acia_p->tdr);
415               //logerror("ACIA6850 #%u: TX START BIT\n", which);
416
417               *acia_p->tx_pin = 0;
418
419               acia_p->tx_bits = acia_p->bits;
420               acia_p->tx_shift = acia_p->tdr;
421
422               // inhibit TDRE bit if Clear-to-Send is high
423
424               if (!(acia_p->status & ACIA6850_STATUS_CTS))
425               {
426                  acia_p->status |= ACIA6850_STATUS_TDRE;
427               }
428
429               acia6850_check_interrupts(which);
430
431               acia_p->tx_state = DATA;
432            }
433         }
274434         break;
275435      }
276436      case DATA:
277437      {
278438         int val = acia_p->tx_shift & 1;
439         //logerror("ACIA6850 #%u: TX DATA BIT %x\n", which, val);
279440
280441         *acia_p->tx_pin = val;
281442         acia_p->tx_parity ^= val;
r1137r1138
283444
284445         if (--(acia_p->tx_bits) == 0)
285446         {
286            acia_p->tx_state = acia_p->parity == NONE ? STOP : PARITY;
447            acia_p->tx_state = (acia_p->parity == NONE) ? STOP : PARITY;
287448         }
288449
289450         break;
r1137r1138
299460            *acia_p->tx_pin = (acia_p->tx_parity & 1) ? 0 : 1;
300461         }
301462
463         //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *acia_p->tx_pin);
302464         acia_p->tx_parity = 0;
303465         acia_p->tx_state = STOP;
304466         break;
305467      }
306468      case STOP:
307469      {
308         /* TODO */
470         //logerror("ACIA6850 #%u: TX STOP BIT\n", which);
309471         *acia_p->tx_pin = 1;
310         acia_p->tx_state = COMPLETE;
472
473         if (acia_p->stopbits == 1)
474         {
475            acia_p->tx_state = START;
476         }
477         else
478         {
479            acia_p->tx_state = STOP2;
480         }
311481         break;
312482      }
313      case COMPLETE:
483      case STOP2:
314484      {
315         /* TDR is now empty */
316         acia_p->status |= STATUS_TDRE;
317
318         /* Transmit timer no longer active */
319         mame_timer_enable(acia_p->tx_timer, 0);
320
485         //logerror("ACIA6850 #%u: TX STOP BIT\n", which);
486         *acia_p->tx_pin = 1;
321487         acia_p->tx_state = START;
322488         break;
323489      }
r1137r1138
330496   int which = param;
331497   acia_6850 *acia_p = &acia[which];
332498
333   switch (acia_p->rx_state)
499   if (acia_p->dcd_pin && *acia_p->dcd_pin)
334500   {
335      case START:
501      acia_p->status |= ACIA6850_STATUS_DCD;
502      acia6850_check_interrupts(which);
503   }
504   else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD)
505   {
506      acia_p->status &= ~ACIA6850_STATUS_DCD;
507   }
508
509   if (acia_p->status & ACIA6850_STATUS_DCD)
510   {
511      acia_p->rx_state = START;
512   }
513   else
514   {
515      switch (acia_p->rx_state)
336516      {
337         /* Wait for low signal */
338         if (*acia_p->rx_pin == 0)
517         case START:
339518         {
340            acia_p->rx_shift = 0;
341            acia_p->rx_bits = acia_p->bits;
342            acia_p->rx_state = DATA;
519            if (*acia_p->rx_pin == 0)
520            {
521               //logerror("ACIA6850 #%u: RX START BIT\n", which);
522               acia_p->rx_shift = 0;
523               acia_p->rx_parity = 0;
524               acia_p->rx_bits = acia_p->bits;
525               acia_p->rx_state = DATA;
526            }
527            break;
343528         }
344         break;
345      }
346      case DATA:
347      {
348         acia_p->rx_shift |= *acia_p->rx_pin ? 0x80 : 0;
349         acia_p->rx_parity ^= *acia_p->rx_pin;
529         case DATA:
530         {
531            //logerror("ACIA6850 #%u: RX DATA BIT %x\n", which, *acia_p->rx_pin);
532            acia_p->rx_shift |= *acia_p->rx_pin ? 0x80 : 0;
533            acia_p->rx_parity ^= *acia_p->rx_pin;
350534
351         if (--acia_p->rx_bits == 0)
352         {
353            acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY;
535            if (--acia_p->rx_bits == 0)
536            {
537               if (acia_p->status & ACIA6850_STATUS_RDRF)
538               {
539                  acia_p->overrun = 1;
540                  acia6850_check_interrupts(which);
541               }
542
543               acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY;
544            }
545            else
546            {
547               acia_p->rx_shift >>= 1;
548            }
549            break;
354550         }
355         else
551         case PARITY:
356552         {
357            acia_p->rx_shift >>= 1;
358         }
359         break;
360      }
361      case PARITY:
362      {
363         acia_p->rx_parity ^= *acia_p->rx_pin;
553            //logerror("ACIA6850 #%u: RX PARITY BIT %x\n", which, *acia_p->rx_pin);
554            acia_p->rx_parity ^= *acia_p->rx_pin;
364555
365         if (acia_p->parity == EVEN)
366         {
367            if (acia_p->rx_parity)
556            if (acia_p->parity == EVEN)
368557            {
369               acia_p->status |= STATUS_PE;
558               if (acia_p->rx_parity)
559               {
560                  acia_p->status |= ACIA6850_STATUS_PE;
561               }
370562            }
563            else
564            {
565               if (!acia_p->rx_parity)
566               {
567                  acia_p->status |= ACIA6850_STATUS_PE;
568               }
569            }
570
571            acia_p->rx_state = STOP;
572            break;
371573         }
372         else
574         case STOP:
373575         {
374            if (!acia_p->rx_parity)
576            if (*acia_p->rx_pin == 1)
375577            {
376               acia_p->status |= STATUS_PE;
578               //logerror("ACIA6850 #%u: RX STOP BIT\n", which);
579               if (acia_p->stopbits == 1)
580               {
581                  acia_p->status &= ~ACIA6850_STATUS_FE;
582
583                  if (!(acia_p->status & ACIA6850_STATUS_RDRF))
584                  {
585                     //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift);
586                     acia_p->rdr = acia_p->rx_shift;
587                     acia_p->status |= ACIA6850_STATUS_RDRF;
588                     acia6850_check_interrupts(which);
589                  }
590
591                  acia_p->rx_state = START;
592               }
593               else
594               {
595                  acia_p->rx_state = STOP2;
596               }
377597            }
598            else
599            {
600               acia_p->status |= ACIA6850_STATUS_FE;
601               acia_p->rx_state = START;
602            }
603            break;
378604         }
379
380         acia_p->rx_parity = 0;
381         acia_p->rx_state = STOP;
382
383         // As long as data is in RDR
384         break;
385      }
386      case STOP:
387      {
388         /* TODO:
389                Multiple stop bits
390                Overrun
391            */
392         acia_p->rx_state = COMPLETE;
393         break;
394      }
395      case COMPLETE:
396      {
397         /*
398                TODO: Check behaviour.
399            */
400         //if (!(acia_p->status & STATUS_RDRF))
605         case STOP2:
401606         {
402            acia_p->rdr = acia_p->rx_shift;
403            acia_p->status |= STATUS_RDRF;
404            acia_p->status |= STATUS_IRQ;
607            if (*acia_p->rx_pin == 1)
608            {
609               //logerror("ACIA6850 #%u: RX STOP BIT\n", which);
610               acia_p->status &= ~ACIA6850_STATUS_FE;
405611
406//              printf("ACIA %d Received full: %x\n", which, acia_p->rdr);
407
408            /* TODO */
409            if (acia_p->ctrl & 0x80)
410            {
411               if (acia_p->int_callback)
612               if (!(acia_p->status & ACIA6850_STATUS_RDRF))
412613               {
413                  acia_p->int_callback(1);
614                  //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift);
615                  acia_p->rdr = acia_p->rx_shift;
616                  acia_p->status |= ACIA6850_STATUS_RDRF;
617                  acia6850_check_interrupts(which);
414618               }
619
620               acia_p->rx_state = START;
415621            }
622            else
623            {
624               acia_p->status |= ACIA6850_STATUS_FE;
625               acia_p->rx_state = START;
626            }
627            break;
416628         }
417
418         acia_p->rx_state = START;
419         break;
420629      }
421630   }
422631}
src/emu/machine/6850acia.h
r1137r1138
33
44#define MAX_ACIA 4
55
6#define ACIA6850_STATUS_RDRF   0x01
7#define ACIA6850_STATUS_TDRE   0x02
8#define ACIA6850_STATUS_DCD      0x04
9#define ACIA6850_STATUS_CTS      0x08
10#define ACIA6850_STATUS_FE      0x10
11#define ACIA6850_STATUS_OVRN   0x20
12#define ACIA6850_STATUS_PE      0x40
13#define ACIA6850_STATUS_IRQ      0x80
14
615struct acia6850_interface
716{
817   int   tx_clock;
r1137r1138
1019
1120   UINT8 *rx_pin;
1221   UINT8 *tx_pin;
22   UINT8 *cts_pin;
23   UINT8 *rts_pin;
24   UINT8 *dcd_pin;
1325
1426   void (*int_callback)(int state);
1527};
src/mess/drivers/atarist.c
r1137r1138
2424
2525   - MSA disk image support
2626   - find missing UK TOS roms
27   - rewrite HD6301 cpu core for serial I/O
2827   - UK keyboard layout for the special keys
2928   - accurate screen timing
3029   - floppy DMA transfer timer
r1137r1138
501500   
502501   if (dmasound.ctrl & 0x80)
503502   {
504      logerror("DMA sound left  %i\n", dmasound.fifo[7 - dmasound.samples]);
503//      logerror("DMA sound left  %i\n", dmasound.fifo[7 - dmasound.samples]);
505504      dmasound.samples--;
506505
507      logerror("DMA sound right %i\n", dmasound.fifo[7 - dmasound.samples]);
506//      logerror("DMA sound right %i\n", dmasound.fifo[7 - dmasound.samples]);
508507      dmasound.samples--;
509508   }
510509   else
511510   {
512      logerror("DMA sound mono %i\n", dmasound.fifo[7 - dmasound.samples]);
511//      logerror("DMA sound mono %i\n", dmasound.fifo[7 - dmasound.samples]);
513512      dmasound.samples--;
514513   }
515514
r1137r1138
12041203/* Machine Drivers */
12051204
12061205static int acia_irq;
1207static UINT8 acia_midi_rx, acia_midi_tx;
1206static UINT8 acia_midi_rx = 1, acia_midi_tx = 1;
12081207
12091208static void acia_interrupt(int state)
12101209{
r1137r1138
12171216   Y2/64,
12181217   &ikbd.rx,
12191218   &ikbd.tx,
1219   NULL,
1220   NULL,
1221   NULL,
12201222   acia_interrupt
12211223};
12221224
r1137r1138
12261228   Y2/64,
12271229   &acia_midi_rx,
12281230   &acia_midi_tx,
1231   NULL,
1232   NULL,
1233   NULL,
12291234   acia_interrupt
12301235};
12311236

Previous 15994 Revisions Next


© 1998-2018 The MESS Team