Previous 15994 Revisions Next

r5421 Thursday 13th August, 2009 at 09:39:11 UTC by Barry Rodewald
[PCW] Re-worked interrupts.
[src/mess/drivers]pcw.c

src/mess/drivers/pcw.c
r5420r5421
121121static UINT8 pcw_banks[4];
122122static unsigned char pcw_bank_force = 0;
123123
124static UINT8 pcw_timer_irq_flag;
125static UINT8 pcw_nmi_flag;
124126
127
128
125129static void pcw_update_interrupt_counter(void)
126130{
127131   /* never increments past 15! */
r5420r5421
142146   NEC765_RDY_PIN_CONNECTED
143147};
144148
145/* determines if int line is held or cleared */
146static void pcw_interrupt_handle(running_machine *machine)
149// set/reset INT and NMI lines
150static void pcw_update_irqs(running_machine *machine)
147151{
148   if (
149      (pcw_interrupt_counter!=0) ||
150      ((fdc_interrupt_code==1) && ((pcw_system_status & (1<<5))!=0))
151      )
152   // set NMI line, remains set until FDC interrupt type is changed
153   if(pcw_nmi_flag != 0)
154      cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE);
155   else
156      cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
157
158   // set IRQ line, timer pulses IRQ line, all other devices hold it as necessary     
159   if(fdc_interrupt_code == 1 && (pcw_system_status & 0x20))
152160   {
153      if(cpu_get_reg(cputag_get_cpu(machine,"maincpu"),Z80_IFF1))
154         cputag_set_input_line(machine, "maincpu", 0,ASSERT_LINE);
161      cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE);
162      return;
155163   }
156   else
164   
165   if(pcw_timer_irq_flag != 0)
157166   {
158      cputag_set_input_line(machine, "maincpu", 0,CLEAR_LINE);
167      cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE);
168      return;
159169   }
170
171   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
160172}
161173
174static TIMER_CALLBACK(pcw_timer_pulse)
175{
176   pcw_timer_irq_flag = 0;
177   pcw_update_irqs(machine);
178}
162179
163
164180/* callback for 1/300ths of a second interrupt */
165181static TIMER_CALLBACK(pcw_timer_interrupt)
166182{
167183   pcw_update_interrupt_counter();
168184
169   pcw_interrupt_handle(machine);
185   pcw_timer_irq_flag = 1;
186   pcw_update_irqs(machine);
187   timer_set(machine,ATTOTIME_IN_USEC(2),NULL,0,pcw_timer_pulse);
170188}
171189
172static int previous_fdc_int_state;
173
174/* set/clear fdc interrupt */
175static void   pcw_trigger_fdc_int(running_machine *machine)
176{
177   int state;
178
179   state = pcw_system_status & (1<<5);
180
181   switch (fdc_interrupt_code)
182   {
183      /* attach fdc to nmi */
184      case 0:
185      {
186         /* I'm assuming that the nmi is edge triggered */
187         /* a interrupt from the fdc will cause a change in line state, and
188            the nmi will be triggered, but when the state changes because the int
189            is cleared this will not cause another nmi */
190         /* I'll emulate it like this to be sure */
191
192         if (state!=previous_fdc_int_state)
193         {
194            if (state)
195            {
196               /* Cleared when FDC interrupt mode is set to INT or nothing */
197               cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE);
198            }
199         }
200      }
201      break;
202
203      /* attach fdc to int */
204      case 1:
205      {
206         pcw_interrupt_handle(machine);
207      }
208      break;
209
210      /* do not interrupt */
211      default:
212         break;
213   }
214
215   previous_fdc_int_state = state;
216}
217
218190/* fdc interrupt callback. set/clear fdc int */
219191static NEC765_INTERRUPT( pcw_fdc_interrupt )
220192{
221
222193   if (state == CLEAR_LINE)
223194      pcw_system_status &= ~(1<<5);
224195   else
196   {
225197      pcw_system_status |= (1<<5);
226
227   pcw_trigger_fdc_int(device->machine);
198      if(fdc_interrupt_code == 0)  // NMI is held until interrupt type is changed
199         pcw_nmi_flag = 1;
200   }
228201}
229202
230203
r5420r5421
270243      memory_install_read8_handler(space,
271244         block * 0x04000 + 0x3ff0, block * 0x04000 + 0x3fff, 0, 0,
272245         pcw_keyboard_r);
273      LOG(("MEM: read block %i -> bank %i\n",block,bank));
246//      LOG(("MEM: read block %i -> bank %i\n",block,bank));
274247   }
275248   else
276249   {
r5420r5421
278251      memory_install_read8_handler(space,
279252         block * 0x04000 + 0x0000, block * 0x04000 + 0x3fff, 0, 0,
280253         (read8_space_func) (STATIC_BANK1 + (FPTR)block));
281      LOG(("MEM: read block %i -> bank %i\n",block,bank));
254//      LOG(("MEM: read block %i -> bank %i\n",block,bank));
282255   }
283256   memory_set_bankptr(machine, block + 1, mess_ram + ((bank * 0x4000) % mess_ram_size));
284257}
r5420r5421
288261static void pcw_update_write_memory_block(running_machine *machine, int block, int bank)
289262{
290263   memory_set_bankptr(machine, block + 5, mess_ram + ((bank * 0x4000) % mess_ram_size));
291   LOG(("MEM: write block %i -> bank %i\n",block,bank));
264//   LOG(("MEM: write block %i -> bank %i\n",block,bank));
292265}
293266
294267
r5420r5421
388361   data = pcw_get_sys_status(space->machine);
389362   /* clear int counter */
390363   pcw_interrupt_counter = 0;
391   /* update interrupt */
392   pcw_interrupt_handle(space->machine);
393364   /* return data */
394365   LOG(("SYS: IRQ counter read, returning %02x\n",data));
395366   return data;
r5420r5421
474445         {
475446            /* yes */
476447
477            pcw_interrupt_handle(space->machine);
448            pcw_update_irqs(space->machine);
478449         }
479450
480         pcw_trigger_fdc_int(space->machine);
481451      }
482452      break;
483453
r5420r5421
496466            /* yes */
497467
498468            /* clear nmi interrupt */
499            cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
469            pcw_nmi_flag = 0;
500470         }
501471
502472         /* re-issue interrupt */
503         pcw_interrupt_handle(space->machine);
473         pcw_update_irqs(space->machine);
504474      }
505475      break;
506476
r5420r5421
513483         fdc_interrupt_code = 2;
514484
515485         /* previously connected to NMI or INT? */
516         if ((fdc_previous_interrupt_code == 0))
486         if ((fdc_previous_interrupt_code == 0) || (fdc_previous_interrupt_code == 1))
517487         {
518488            /* yes */
519489
520490            /* Clear NMI */
521            cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
522
491            pcw_nmi_flag = 0;
523492         }
524         pcw_interrupt_handle(space->machine);
493         pcw_update_irqs(space->machine);
525494
526495      }
527496      break;
r5420r5421
657626static WRITE8_HANDLER(pcw_expansion_w)
658627{
659628   logerror("pcw expansion w: %04x %02x\n",offset+0x080, data);
660
661
662
663
664
665
666629}
667630
668631static READ8_HANDLER(pcw_fdc_r)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team