Previous 15994 Revisions Next

r1191 Friday 26th October, 2007 at 13:03:24 UTC by Curt Coder
[MFP68901] Fixed interrupt handling
[src/mess/drivers]atarist.c x68k.c
[src/mess/machine]68901mfp.c 68901mfp.h
[src/mess/video]atarist.c

src/mess/video/atarist.c
r1190r1191
101101         shifter.h = CLEAR_LINE;
102102         break;
103103      case ATARIST_HBSTART_PAL/4:
104         cpunum_set_input_line(0, MC68000_IRQ_2, ASSERT_LINE);
104         cpunum_set_input_line(0, MC68000_IRQ_2, HOLD_LINE);
105105         shifter.ofs += (shifter.lineofs * 2); // STe
106106         break;
107107      }
r1190r1191
115115         shifter.v = CLEAR_LINE;
116116         break;
117117      case ATARIST_VBSTART_PAL:
118         cpunum_set_input_line(0, MC68000_IRQ_4, ASSERT_LINE);
119         shifter.ofs = shifter.base;
118         if (hcount == 0)
119         {
120            cpunum_set_input_line(0, MC68000_IRQ_4, HOLD_LINE);
121            shifter.ofs = shifter.base;
122         }
120123         break;
121124      }
122125   }
r1190r1191
133136         shifter.h = CLEAR_LINE;
134137         break;
135138      case ATARIST_HBSTART_NTSC/4:
136         cpunum_set_input_line(0, MC68000_IRQ_2, ASSERT_LINE);
139         cpunum_set_input_line(0, MC68000_IRQ_2, HOLD_LINE);
137140         shifter.ofs += (shifter.lineofs * 2); // STe
138141         break;
139142      }
r1190r1191
147150         shifter.v = CLEAR_LINE;
148151         break;
149152      case ATARIST_VBSTART_NTSC:
150         cpunum_set_input_line(0, MC68000_IRQ_4, ASSERT_LINE);
151         shifter.ofs = shifter.base;
153         if (hcount == 0)
154         {
155            cpunum_set_input_line(0, MC68000_IRQ_4, HOLD_LINE);
156            shifter.ofs = shifter.base;
157         }
152158         break;
153159      }
154160   }
src/mess/machine/68901mfp.c
r1190r1191
22
33   TODO:
44
5   - poll TAI/TBI pins
56   - daisy chaining
67   - correct irq_timer period
7   - disable GPIO3/4 interrupts when timer A/B in event count or pulse mode
8   - disable GPIO3/4 interrupts when timer A/B in pulse mode
89   - spurious interrupt
910
1011      If you look at the MFP datasheet it is obvious that it can generate the conditions for a spurious interrupt.
r1190r1191
6263   int   rx_parity, tx_parity;
6364   int   rx_state, tx_state, xmit_state;
6465   int rxtx_word, rxtx_start, rxtx_stop;
66
6567   mame_timer *rx_timer, *tx_timer;
6668} mfp_68901;
6769
r1190r1191
9092
9193static const int PRESCALER[] = { 0, 4, 10, 16, 50, 64, 100, 200 };
9294
95static void mfp68901_check_interrupts(int which)
96{
97   mfp_68901 *mfp_p = &mfp[which];
98
99   int intr = (mfp_p->ipr & mfp_p->imr) ? HOLD_LINE : CLEAR_LINE;
100   mfp_p->intf->irq_callback(which, intr);
101}
102
93103static void mfp68901_poll_gpio(int which)
94104{
95105   mfp_68901 *mfp_p = &mfp[which];
r1190r1191
123133   mfp_p->gpip = (gpio & ~mfp_p->ddr) | (mfp_p->gpip & mfp_p->ddr);
124134}
125135
126static void mfp68901_irq_ack(int which)
127{
128   mfp_68901 *mfp_p = &mfp[which];
129
130   int ch;
131
132   for (ch = 15; ch >= 0; ch--) // loop thru each channel from 15 to 0
133   {
134      if (BIT(mfp_p->isr, ch)) // if interrupt channel is in service...
135      {
136         return; // don't process lower priority channels
137      }
138
139      if (BIT(mfp_p->imr, ch)) // if interrupt mask bit is set...
140      {
141         if (BIT(mfp_p->ipr, ch)) // AND interrupt pending bit is set...
142         {
143            logerror("MFP68901 #%u Interrupt Fired on Channel %u\n", which, ch);
144
145            mfp_p->ipr &= ~(1 << ch); // clear interrupt pending bit
146
147            if (mfp_p->vr & MFP68901_VR_S) // if software end-of-interrupt mode is enabled...
148            {
149               mfp_p->isr |= (1 << ch); // set interrupt in service bit (bit will be cleared later by the interrupt service routine)
150            }
151
152            mfp_p->intf->irq_callback(which, HOLD_LINE, (mfp_p->vr & 0xf0) | ch); // fire interrupt callback
153
154            return;
155         }
156      }
157   }
158}
159
160136static TIMER_CALLBACK( mfp68901_tick )
161137{
162138   mfp68901_poll_gpio(param);
163   mfp68901_irq_ack(param);
139   mfp68901_check_interrupts(param);
164140}
165141
166142/* USART */
r1190r1191
586562      logerror("MFP68901 #%u Interrupt Enable Register A : %x\n", which, data);
587563      mfp_p->ier = (data << 8) | (mfp_p->ier & 0xff);
588564      mfp_p->ipr &= mfp_p->ier;
565      mfp68901_check_interrupts(which);
589566      break;
590567
591568   case MFP68901_REGISTER_IERB:
592569      logerror("MFP68901 #%u Interrupt Enable Register B : %x\n", which, data);
593570      mfp_p->ier = (mfp_p->ier & 0xff00) | data;
594571      mfp_p->ipr &= mfp_p->ier;
572      mfp68901_check_interrupts(which);
595573      break;
596574
597575   case MFP68901_REGISTER_IPRA:
598576      logerror("MFP68901 #%u Interrupt Pending Register A : %x\n", which, data);
599577      mfp_p->ipr &= (data << 8) | (mfp_p->ipr & 0xff);
578      mfp68901_check_interrupts(which);
600579      break;
601580
602581   case MFP68901_REGISTER_IPRB:
603582      logerror("MFP68901 #%u Interrupt Pending Register B : %x\n", which, data);
604583      mfp_p->ipr &= (mfp_p->ipr & 0xff00) | data;
584      mfp68901_check_interrupts(which);
605585      break;
606586
607587   case MFP68901_REGISTER_ISRA:
r1190r1191
618598      logerror("MFP68901 #%u Interrupt Mask Register A : %x\n", which, data);
619599      mfp_p->imr = (data << 8) | (mfp_p->imr & 0xff);
620600      mfp_p->isr &= mfp_p->imr;
601      mfp68901_check_interrupts(which);
621602      break;
622603
623604   case MFP68901_REGISTER_IMRB:
624605      logerror("MFP68901 #%u Interrupt Mask Register B : %x\n", which, data);
625606      mfp_p->imr = (mfp_p->imr & 0xff00) | data;
626607      mfp_p->isr &= mfp_p->imr;
608      mfp68901_check_interrupts(which);
627609      break;
628610
629611   case MFP68901_REGISTER_VR:
r1190r1191
10731055   }
10741056}
10751057
1076void mfp68901_tai_w(int which, int value)
1077{
1078   mfp68901_ti_w(which, MFP68901_TIMER_A, value);
1079}
1080
1081void mfp68901_tbi_w(int which, int value)
1082{
1083   mfp68901_ti_w(which, MFP68901_TIMER_B, value);
1084}
1085
10861058static TIMER_CALLBACK( timer_a )
10871059{
10881060   mfp68901_timer_count(param, MFP68901_TIMER_A);
r1190r1191
11031075   mfp68901_timer_count(param, MFP68901_TIMER_D);
11041076}
11051077
1078/* External Interface */
1079
1080void mfp68901_tai_w(int which, int value)
1081{
1082   mfp68901_ti_w(which, MFP68901_TIMER_A, value);
1083}
1084
1085void mfp68901_tbi_w(int which, int value)
1086{
1087   mfp68901_ti_w(which, MFP68901_TIMER_B, value);
1088}
1089
1090int mfp68901_get_vector(int which)
1091{
1092   mfp_68901 *mfp_p = &mfp[which];
1093
1094   int ch;
1095
1096   for (ch = 15; ch >= 0; ch--)
1097   {
1098      if (BIT(mfp_p->ipr, ch))
1099      {
1100         if (mfp_p->vr & MFP68901_VR_S)
1101         {
1102            mfp_p->isr |= (1 << ch);
1103         }
1104
1105         mfp_p->ipr &= ~(1 << ch);
1106
1107         mfp68901_check_interrupts(which);
1108
1109         return (mfp_p->vr & 0xf0) | ch;
1110      }
1111   }
1112
1113   return MC68000_INT_ACK_SPURIOUS;
1114}
1115
1116void mfp68901_reset(int which)
1117{
1118   mfp68901_register_w(which, MFP68901_REGISTER_GPIP, 0);
1119   mfp68901_register_w(which, MFP68901_REGISTER_AER, 0);
1120   mfp68901_register_w(which, MFP68901_REGISTER_DDR, 0);
1121   mfp68901_register_w(which, MFP68901_REGISTER_IERA, 0);
1122   mfp68901_register_w(which, MFP68901_REGISTER_IERB, 0);
1123   mfp68901_register_w(which, MFP68901_REGISTER_IPRA, 0);
1124   mfp68901_register_w(which, MFP68901_REGISTER_IPRB, 0);
1125   mfp68901_register_w(which, MFP68901_REGISTER_ISRA, 0);
1126   mfp68901_register_w(which, MFP68901_REGISTER_ISRB, 0);
1127   mfp68901_register_w(which, MFP68901_REGISTER_IMRA, 0);
1128   mfp68901_register_w(which, MFP68901_REGISTER_IMRB, 0);
1129   mfp68901_register_w(which, MFP68901_REGISTER_VR, 0);
1130   mfp68901_register_w(which, MFP68901_REGISTER_TACR, 0);
1131   mfp68901_register_w(which, MFP68901_REGISTER_TBCR, 0);
1132   mfp68901_register_w(which, MFP68901_REGISTER_TCDCR, 0);
1133   mfp68901_register_w(which, MFP68901_REGISTER_SCR, 0);
1134   mfp68901_register_w(which, MFP68901_REGISTER_UCR, 0);
1135   mfp68901_register_w(which, MFP68901_REGISTER_RSR, 0);
1136}
1137
11061138void mfp68901_config(int which, const mfp68901_interface *intf)
11071139{
11081140   mfp_68901 *mfp_p = &mfp[which];
r1190r1191
11761208   state_save_register_item("mfp68901", which, mfp_p->next_rsr);
11771209}
11781210
1211/* Read/Write Handlers */
1212
11791213READ16_HANDLER( mfp68901_0_register_msb_r ) { return mfp68901_register_r(0, offset) << 8; }
11801214READ16_HANDLER( mfp68901_1_register_msb_r ) { return mfp68901_register_r(1, offset) << 8; }
11811215READ16_HANDLER( mfp68901_2_register_msb_r ) { return mfp68901_register_r(2, offset) << 8; }
src/mess/machine/68901mfp.h
r1190r1191
33
44#include "driver.h"
55#include "timer.h"
6#include "cpu/m68000/m68000.h"
67
78#define MAX_MFP   4
89
r1190r1191
1718
1819   void (*to_w)(int which, int timer, int value);
1920
20   void (*irq_callback)(int which, int state, int vector);
21   void (*irq_callback)(int which, int state);
2122
2223   read8_handler gpio_r;
2324   write8_handler gpio_w;
r1190r1191
197198#define MFP68901_TSR_UNDERRUN_ERROR      0x40
198199#define MFP68901_TSR_BUFFER_EMPTY      0x80
199200
200void mfp68901_config(int which, const mfp68901_interface *intf);
201/* External Interface */
201202
202203void mfp68901_tai_w(int which, int value);
203204void mfp68901_tbi_w(int which, int value);
204205
206int mfp68901_get_vector(int which);
207
208void mfp68901_reset(int which);
209
210void mfp68901_config(int which, const mfp68901_interface *intf);
211
212/* Read/Write Handlers */
213
205214READ16_HANDLER( mfp68901_0_register_msb_r );
206215READ16_HANDLER( mfp68901_1_register_msb_r );
207216READ16_HANDLER( mfp68901_2_register_msb_r );
src/mess/drivers/x68k.c
r1190r1191
14081408      mame_timer_set(MAME_TIME_IN_CYCLES(32,0),param,x68k_delayed_irq);
14091409      return;
14101410   }
1411   current_vector[6] = param;
1412   cpunum_set_input_line_and_vector(0,6,HOLD_LINE,param);
1411//   current_vector[6] = param;
1412   cpunum_set_input_line(0,6,HOLD_LINE);
14131413}
14141414
1415void mfp_irq_callback(int which, int state, int vector)
1415void mfp_irq_callback(int which, int state)
14161416{
1417   if(state == HOLD_LINE)
1417   if(state == CLEAR_LINE)
1418      cpunum_set_input_line(0,6,state);
1419   else
14181420   {
1419      if((sys.ioc.irqstatus & 0xc0) != 0)  // if the FDC is busy, then we don't want to miss that IRQ
1420      {
1421         mame_timer_set(MAME_TIME_IN_CYCLES(32,0),vector,x68k_delayed_irq);
1422         return;
1423      }
1424      current_vector[6] = vector;
1425      cpunum_set_input_line_and_vector(0,6,state,vector);
1426//      logerror("MFP IRQ callback: state=%i,vector=0x%02x\n",state,vector);
1421//      if((sys.ioc.irqstatus & 0xc0) != 0)  // if the FDC is busy, then we don't want to miss that IRQ
1422//      {
1423//         mame_timer_set(MAME_TIME_IN_CYCLES(32,0),0,x68k_delayed_irq);
1424//         return;
1425//      }
1426//      current_vector[6] = vector;
1427      cpunum_set_input_line(0,6,state);
1428//      logerror("MFP IRQ callback: state=%i\n",state);
14271429   }
14281430}
14291431
r1190r1191
14451447
14461448static int x68k_int_ack(int line)
14471449{
1448   cpunum_set_input_line_and_vector(0,line,CLEAR_LINE,current_vector[line]);
1449   if(line == 1)  // IOSC
1450   {
1451      sys.ioc.irqstatus &= ~0xf0;
1452   }
1453   if(line == 5)  // SCC
1454   {
1455      sys.mouse.irqactive = 0;
1456   }
14571450   if(line == 6)  // MFP
14581451   {
14591452//      if(sys.mfp.isra & 0x10)
r1190r1191
14761469//            sys.mfp.isra |= (1 << (sys.mfp.current_irq - 8));
14771470//      }
14781471      sys.mfp.current_irq = -1;
1472      current_vector[6] = mfp68901_get_vector(0);
1473      logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[6],line);
1474      return current_vector[6];
14791475   }
14801476
1477   cpunum_set_input_line_and_vector(0,line,CLEAR_LINE,current_vector[line]);
1478   if(line == 1)  // IOSC
1479   {
1480      sys.ioc.irqstatus &= ~0xf0;
1481   }
1482   if(line == 5)  // SCC
1483   {
1484      sys.mouse.irqactive = 0;
1485   }
1486
14811487   logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[line],line);
14821488   return current_vector[line];
14831489}
r1190r1191
15171523
15181524static mfp68901_interface mfp_interface =
15191525{
1520   4000000, // 4MHz clock
1521   4000000,
1526   2000000, // 4MHz clock
1527   2000000,
1528   MFP68901_TDO_LOOPBACK,
15221529   0,
1523   0,
15241530   &mfp_key,  // Rx
15251531   NULL,      // Tx
15261532   NULL,
src/mess/drivers/atarist.c
r1190r1191
7676
7777   if ((fdc.mode & ATARIST_FLOPPY_MODE_DMA_DISABLE) == 0)
7878   {
79      if (fdc.sectors > 0)
79      while (fdc.sectors > 0)
8080      {
8181         if (fdc.mode & ATARIST_FLOPPY_MODE_WRITE)
8282         {
r1190r1191
112112   switch (event)
113113   {
114114   case WD17XX_IRQ_SET:
115      fdc.irq = ASSERT_LINE;
115      fdc.irq = 1;
116116      break;
117117
118118   case WD17XX_IRQ_CLR:
119      fdc.irq = CLEAR_LINE;
119      fdc.irq = 0;
120120      break;
121121
122122   case WD17XX_DRQ_SET:
123      fdc.status &= ~ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
123      fdc.status |= ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
124124      atarist_fdc_dma_transfer();
125125      break;
126126
127127   case WD17XX_DRQ_CLR:
128      fdc.status |= ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
128      fdc.status &= ~ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
129129      break;
130130   }
131131}
r1190r1191
191191   if ((data & ATARIST_FLOPPY_MODE_WRITE) != (fdc.mode & ATARIST_FLOPPY_MODE_WRITE))
192192   {
193193      fdc.status = 0;
194      fdc.sectors = 0;
194195   }
195196
196197   fdc.mode = data;
r1190r1191
217218   {
218219   case 0:
219220      fdc.dmabase = (fdc.dmabase & 0x00ffff) | ((data & 0xff) << 16);
220      fdc.dmabytes = ATARIST_FLOPPY_BYTES_PER_SECTOR;
221221      break;
222222   case 1:
223      fdc.dmabase = (fdc.dmabase & 0xff00ff) | ((data & 0xff) << 8);
224      fdc.dmabytes = ATARIST_FLOPPY_BYTES_PER_SECTOR;
223      fdc.dmabase = (fdc.dmabase & 0x0000ff) | ((data & 0xff) << 8);
225224      break;
226225   case 2:
227      fdc.dmabase = (fdc.dmabase & 0xffff00) | (data & 0xff);
228      fdc.dmabytes = ATARIST_FLOPPY_BYTES_PER_SECTOR;
226      fdc.dmabase = data & 0xff;
229227      break;
230228   }
229   
230   fdc.dmabytes = ATARIST_FLOPPY_BYTES_PER_SECTOR;
231231}
232232
233233/* MMU */
r1190r1191
883883   AM_RANGE(0xff8a38, 0xff8a39) AM_READWRITE(atarist_blitter_count_y_r, atarist_blitter_count_y_w)
884884   AM_RANGE(0xff8a3a, 0xff8a3b) AM_READWRITE(atarist_blitter_op_r, atarist_blitter_op_w)
885885   AM_RANGE(0xff8a3c, 0xff8a3d) AM_READWRITE(atarist_blitter_ctrl_r, atarist_blitter_ctrl_w)
886   AM_RANGE(0xfffa00, 0xfffa3f) AM_READWRITE(mfp68901_0_register_lsb_r, mfp68901_0_register_msb_w)
886   AM_RANGE(0xfffa00, 0xfffa3f) AM_READWRITE(mfp68901_0_register_lsb_r, mfp68901_0_register_lsb_w)
887887//   AM_RANGE(0xfffa40, 0xfffa57) AM_READWRITE(megast_fpu_r, megast_fpu_w)
888888   AM_RANGE(0xfffc00, 0xfffc01) AM_READWRITE(acia6850_0_stat_msb_r, acia6850_0_ctrl_msb_w)
889889   AM_RANGE(0xfffc02, 0xfffc03) AM_READWRITE(acia6850_0_data_msb_r, acia6850_0_data_msb_w)
r1190r1191
988988   AM_RANGE(0xff8a3a, 0xff8a3b) AM_READWRITE(atarist_blitter_op_r, atarist_blitter_op_w)
989989   AM_RANGE(0xff8a3c, 0xff8a3d) AM_READWRITE(atarist_blitter_ctrl_r, atarist_blitter_ctrl_w)
990990   AM_RANGE(0xff8e20, 0xff8e21) AM_READWRITE(megaste_cache_r, megaste_cache_w)
991   AM_RANGE(0xfffa00, 0xfffa3f) AM_READWRITE(mfp68901_0_register_lsb_r, mfp68901_0_register_msb_w)
991   AM_RANGE(0xfffa00, 0xfffa3f) AM_READWRITE(mfp68901_0_register_lsb_r, mfp68901_0_register_lsb_w)
992992//   AM_RANGE(0xfffa40, 0xfffa5f) AM_READWRITE(megast_fpu_r, megast_fpu_w)
993993   AM_RANGE(0xff8c80, 0xff8c87) AM_READWRITE(megaste_scc8530_r, megaste_scc8530_w)
994994   AM_RANGE(0xfffc00, 0xfffc01) AM_READWRITE(acia6850_0_stat_msb_r, acia6850_0_ctrl_msb_w)
r1190r1191
13881388   return data;
13891389}
13901390
1391static void mfp_interrupt(int which, int state, int vector)
1391static int atarist_int_ack(int line)
13921392{
1393   cpunum_set_input_line_and_vector(0, MC68000_IRQ_6, state, vector);
1393   if (line == MC68000_IRQ_6)
1394   {
1395      return mfp68901_get_vector(0);
1396   }
1397
1398   return MC68000_INT_ACK_AUTOVECTOR;
13941399}
13951400
1401static void mfp_interrupt(int which, int state)
1402{
1403   cpunum_set_input_line(0, MC68000_IRQ_6, state);
1404}
1405
13961406static UINT8 mfp_rx, mfp_tx;
13971407
13981408static const mfp68901_interface mfp_intf =
r1190r1191
14581468static void atarist_state_save(void)
14591469{
14601470   memset(&fdc, 0, sizeof(fdc));
1471
1472   fdc.status |= ATARIST_FLOPPY_STATUS_DMA_ERROR;
1473
14611474   memset(&ikbd, 0, sizeof(ikbd));
14621475
14631476   state_save_register_global(mmu);
r1190r1191
14921505   acia6850_config(0, &acia_ikbd_intf);
14931506   acia6850_config(1, &acia_midi_intf);
14941507   mfp68901_config(0, &mfp_intf);
1508
1509   cpunum_set_irq_callback(0, atarist_int_ack);
14951510}
14961511
14971512static struct rp5c15_interface rtc_intf =
r1190r1191
15791594   acia6850_config(1, &acia_midi_intf);
15801595   mfp68901_config(0, &atariste_mfp_intf);
15811596
1597   cpunum_set_irq_callback(0, atarist_int_ack);
1598
15821599   dmasound_timer = mame_timer_alloc(atariste_dmasound_tick);
15831600   microwire_timer = mame_timer_alloc(atariste_microwire_tick);
15841601}
r1190r1191
17141731   acia6850_config(1, &acia_midi_intf);
17151732   mfp68901_config(0, &stbook_mfp_intf);
17161733   rp5c15_init(&rtc_intf);
1734
1735   cpunum_set_irq_callback(0, atarist_int_ack);
17171736}
17181737
17191738static MACHINE_DRIVER_START( atarist )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team